edgex簡述

一.概述

Edgex foundry是一個Linux 基金會運營的開源邊緣計算物聯網軟件框架項目,該項目的核心是基於與硬件和操做系統徹底無關的參考軟件平臺創建的互操做框架,使能即插即用的組件生態系統,統一市場,加速物聯網方案的部署。EdgeX Foundry 使有意參與的各方在開放與互操做的物聯網方案中自由協做,不管他們是使用公開標準或私有方案。html

EdgeX Foundry微服務集合構成了四個微服務層及兩個加強的基礎系統服務,四個微服務層包含了從物理域數據採集到信息域數據處理等一系列的服務,另外兩個基礎系統服務爲該四個服務層提供支撐服務。java

四個微服務層從物理層到應用層依次爲:設備服務層(device service),核心服務層(core service),支持服務層(supporting service),開放服務層(export service)。git

兩個加強基礎服務:security和system Management。github

在edgex中區分南北向:South Side和North Sideweb

South Side:All IoT 設備、傳感器、執行器等數據的來源端。docker

North Side:雲端(the Cloud),數據在這裏存儲、匯聚、分析、整合等。segmentfault

二.Core Services

核心服務層包含下列組件:api

Core data:負責採集南向設備層數據,並向北向服務提供數據服務。a persistence repository and associated management service for data collected from the south side objects.安全

Command:負責向南向設備發送命令。a service that facilitates and controls actuation requests from the north side to the south side.服務器

Metadata:負責設備自身能力描述,提供配置新設備並將它們與其擁有的設備服務配對的功能。

a repository and associated management service of metadata about the objects that are connected to EdgeX Foundry. Provides the capability to provision new devices and pair them with their owning device services.

Registry&config:負責服務註冊與發現,爲其餘EdgeX Foundry微服務提供關於EdgeX Foundry內相關服務的信息,包括微服務配置屬性。採用開源consul實現。

provides other EdgeX Foundry microservices with information about associated services within EdgeX Foundry and microservices configuration properties (i.e. - a repository of initialization values).

Registry&config微服務向EdgeX Foundry框架範圍的微服務提供集中式管理,主要包含兩個方面:

Edgex Foundry框架範圍內全部微服務的配置參數與操做參數;

Edgex Foundry框架範圍內全部微服務的位置與狀態;

當每一個edgex微服務啓動時,都應該向registry&config註冊本身,以便registry&config以後能夠ping其餘微服務以準確獲取相關微服務的健康情況,從而爲edgex或第三方提供權威的微服務狀態信息。

三.Supporting Services

支持服務(SS)層包含普遍的微服務,該層微服務主要提供邊緣分析服務和智能分析服務。 此外,該層還爲EdgeXmicorservices提供支持功能,如日誌記錄,調度和數據清理(清理)。

規則引擎,警報和通知微服務 在SS層內,由於它們在Core Services層上運行。 本地分析功能(目前僅以簡單的規則引擎實現基本的分析功能)也位於此層。

四.Export Services

在必要狀況下,EdgeX Foundry須要能夠獨立於其餘系統運行。Edgex Foundry所依存的網關一般會在獨立非聯網環境下部署,同時監管一組傳感器或設備。當網關在不聯網環境下運行時,其監管的傳感器及設備是不受外界環境監管或控制的。所以EdgeX Foundry在不鏈接北向應用的狀況下,是能夠長時間獨立運行的。不過EdgeX Foundry收集的數據總歸仍是須要按期或不按期的傳輸給北向應用(一般爲雲端系統)。開放服務層就是爲實現數據的傳輸。開放服務層提供了一組微服務實現如下功能:

● 北向應用能夠在網關注冊,並獲取其感興趣的南向設備的數據;

● 通知數據什麼時候被髮往何地;

● 通知數據傳輸格式;

本層提供的微服務:

Client Registration

Distribution

五.Device Services

設備服務層負責與南向設備交互。設備服務是與南向設備或物聯網對象交互的邊緣鏈接器,包括各類傳感器、執行器等。

設備服務能夠同時服務於一個或多個設備(傳感器,致動器等)。 DS管理的「設備」可能不是簡單的單一物理設備。它多是EdgeX Foundry的另外一個網關(以及該網關的全部設備),設備管理器或設備聚合器,充當設備或設備集合。

設備服務層的微服務經過每一個物聯網對象自己的協議與設備,傳感器,執行器和其餘物聯網對象進行通訊。DS層將由IoT對象生成和傳遞的數據轉換爲常見的EdgeX Foundry數據結構,並將轉換後的數據發送到Core Services Layer以及EdgeX Foundry其餘層的其餘微服務。

六.系統服務層

系統服務包含安全基礎服務和系統管理服務,目前服務不完善。

七.應用

可經過edgex提供的容器體驗edgex服務,參照https://docs.edgexfoundry.org/Ch-Walkthrough.html。

1)安裝完docker和docker-compose後,執行以下命令完成鏡像下載和啓動:

wget https://raw.githubusercontent.com/edgexfoundry/developer-scripts/master/compose-files/docker-compose.yml
docker-compose up -d

一段時間後,全部相關服務都啓動成功:

~/edgex/0.7.1_docker$ docker-compose up -d Creating network "071_docker_edgex-network" with driver "bridge" Creating edgex-support-rulesengine ... done Creating edgex-files ... done Creating edgex-core-consul ... done Creating edgex-mongo ... done Creating edgex-config-seed ... done Creating edgex-support-logging ... done Creating edgex-core-data ... done Creating edgex-support-notifications ... done Creating edgex-core-metadata ... done Creating edgex-export-client ... done Creating edgex-core-command ... done Creating edgex-support-scheduler ... done Creating edgex-export-distro ... done ~/edgex/0.7.1_docker$ docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------------------------------------------------ edgex-config-seed             /bin/sh -c /edgex/cmd/conf ...   Exit 0 edgex-core-command            /core-command --consul --p ...   Up       0.0.0.0:48082->48082/tcp edgex-core-consul             docker-entrypoint.sh agent ...   Up       8300/tcp, 8301/tcp, 8301/udp, 8302/tcp, 8302/udp, 0.0.0.0:8400->8400/tcp, 0.0.0.0:8500->8500/tcp,0.0.0.0:8600->8600/tcp, 8600/udp edgex-core-data               /core-data --consul --prof ...   Up       0.0.0.0:48080->48080/tcp, 0.0.0.0:5563->5563/tcp edgex-core-metadata           /core-metadata --consul -- ...   Up       0.0.0.0:48081->48081/tcp, 48082/tcp edgex-export-client           /export-client --consul -- ...   Up       0.0.0.0:48071->48071/tcp edgex-export-distro           /export-distro --consul -- ...   Up       0.0.0.0:48070->48070/tcp, 0.0.0.0:5566->5566/tcp edgex-files                   /bin/sh -c /usr/bin/tail - ... Up edgex-mongo                   docker-entrypoint.sh /bin/ ...   Up       0.0.0.0:27017->27017/tcp edgex-support-logging         /support-logging --consul  ...   Up       0.0.0.0:48061->48061/tcp edgex-support-notifications   /support-notifications --c ...   Up       0.0.0.0:48060->48060/tcp edgex-support-rulesengine     /bin/sh -c java -jar -Djav ...   Up       0.0.0.0:48075->48075/tcp edgex-support-scheduler       /support-scheduler --consu ...   Up       0.0.0.0:48085->48085/tcp

consul服務對外提供web服務,可經過hostip:8500訪問管理服務。

此外,edgex有專門的ui項目:https://github.com/edgexfoundry/edgex-ui-go,運行以下命令啓動:

docker run -it -d -p 4000:4000 --name edgex-ui-go edgexfoundry/docker-edgex-ui-go:0.1.1

可經過hostip:4000訪問,user/passwd均爲admin。

2)參考https://docs.edgexfoundry.org/Ch-Walkthrough.html進行API walkthrough測試,將例子API中localhost改成主機的IP地址,好比 http://localhost:48081/api/v1/addressable 修改成

http://192.168.134.144:48081/api/v1/addressable。 

可在主機192.168.134.144上搭建mosquitto服務器,並訂閱主題a/b/c:

mosquitto_sub -t a/b/c

Register an Export Client時須要將mqtt broker配置爲上文搭建的mosquitto代理服務器,MQTT topic配置爲 a/b/c

POST to http://192.168.134.144:48071/api/v1/registration
{"name":"MyMQTTTopic","addressable":{"name":"MyMQTTBroker","protocol":"TCP","address":"192.168.134.144","port":1883,"publisher":"EdgeXExportPublisher","user":"wang","password":"mypass","topic":"a/b/c"},"format":"JSON","enable":true,"destination":"MQTT_TOPIC"}

發送數據:

POST to http://192.168.134.144:48080/api/v1/event
{"device":"countcamera1","readings":[{"name":"humancount","value":"12"},{"name":"caninecount","value":"30"}]}

mosquitto也會接受到相應數據:

{"id":"5cd13e6b0e3608000187ec7e","pushed":0,"device":"countcamera1","created":1557216875909,"mo,"event":null,"readings":[{"id":"5cd13e6b0e3608000187ec7f","pushed":0,"created":1557216875909,"ntcamera1","name":"humancount","value":"12"},{"id":"5cd13e6b0e3608000187ec80","pushed":0,"created":0,"device":"countcamera1","name":"caninecount","value":"30"}]}

八.Walk Through

1.準備工做

安裝docker、docker-compose,併成功拉取edgex相關官方鏡像,執行以下命令中止並清除edgex容器及數據。

docker-compose down sudo rm /var/lib/docker/volumes/docker_* -rf systemctl restart docker

2.啓動edgex相關服務,不啓動任何device相關服務(包含device-virtual)。

可經過修改docker-compose.yml註釋掉Device Services、UIs、Tooling全部服務。

docker-compose up -d

主機IP地址爲192.168.134.144,可經過以下命令確認edgex容器中目前沒有設備數據:

# curl http://192.168.134.144:48080/api/v1/event
[]

3.註冊設備服務和設備的地址

註冊設備服務:

POSTtohttp://192.168.134.144:48081/api/v1/addressable
BODY:{"name":"camera control","protocol":"HTTP","address":"172.20.0.1","port":49977,"path":"/cameracontrol","publisher":"none","user":"none","password":"none","topic":"none"}

註冊設備:

POSTtohttp://192.168.134.144:48081/api/v1/addressable
BODY:{"name":"camera1 address","protocol":"HTTP","address":"172.20.0.1","port":49999,"path":"/camera1","publisher":"none","user":"none","password":"none","topic":"none"}

注意:修改了主機IP和docker IP,須要根據測試環境配置。docker IP指向edgex docker容器的gateway,可經過docker inspect edgex-mongo查看。

POST成功後,會收到註冊ID,形如:

5cd4e6479f8fc2000172aba4

可經過 GET to http://192.168.134.144:48081/api/v1/addressable獲取剛註冊的信息。

4.註冊數據描述

註冊humancount、caninecount、depth、duration、cameraerror數據,用於描述設備相關數據及錯誤。

POSTtohttp://192.168.134.144:48080/api/v1/valuedescriptor
BODY:{"name":"humancount","description":"people count","min":"0","max":"100","type":"I","uomLabel":"count","defaultValue":"0","formatting":"%s","labels":["count","humans"]} POSTtohttp://192.168.134.144:48080/api/v1/valuedescriptor
BODY:{"name":"caninecount","description":"dog count","min":"0","max":"100","type":"I","uomLabel":"count","defaultValue":"0","formatting":"%s","labels":["count","canines"]} POSTtohttp://192.168.134.144:48080/api/v1/valuedescriptor
BODY:{"name":"depth","description":"scan distance","min":"1","max":"10","type":"I","uomLabel":"feet","defaultValue":"1","formatting":"%s","labels":["scan","distance"]} POSTtohttp://192.168.134.144:48080/api/v1/valuedescriptor
BODY:{"name":"duration","description":"time between events","min":"10","max":"180","type":"I","uomLabel":"seconds","defaultValue":"10","formatting":"%s","labels":["duration","time"]} POSTtohttp://192.168.134.144:48080/api/v1/valuedescriptor
BODY:{"name":"cameraerror","description":"error response message from a camera","min":"","max":"","type":"S","uomLabel":"","defaultValue":"error","formatting":"%s","labels":["error","message"]}

一樣返回註冊ID。

5.註冊設備Profile

Device Profile定義設備,包含設備類型、設備數據、設備支持的命令等。

POSTtohttp://192.168.134.144:48081/api/v1/deviceprofile/uploadfile
No headers FORM-DATA: key: 「file」 value: EdgeX_CameraMonitorProfile.yml

一樣返回註冊ID

6.註冊設備服務

POSTtohttp://192.168.134.144:48081/api/v1/deviceservice
BODY:{"name":"camera control device service","description":"Manage human and dog counting cameras","labels":["camera","counter"],"adminState":"unlocked","operatingState":"enabled","addressable":{"name":"camera control"}}

7.模擬設備

POSTtohttp://192.168.134.144:48081/api/v1/device
BODY:{"name":"countcamera1","description":"human and dog counting camera #1","adminState":"unlocked","operatingState":"enabled","addressable":{"name":"camera1 address"},"labels":["camera","counter"],"location":"","service":{"name":"camera control device service"},"profile":{"name":"camera monitor profile"}}

8.覈實設備和服務

GETtohttp://192.168.134.144:48081/api/v1/deviceservice
GETtohttp://192.168.134.144:48081/api/v1/device

返回註冊的設備和服務。

9.執行命令

列出設備支持的命令:

GETtohttp://192.168.134.144:48082/api/v1/device/name/countcamera1
GET to http://192.168.134.144:48082/api/v1/device

device id以下圖標註:

列出設備支持的數據:

GETtohttp://192.168.134.144:48080/api/v1/valuedescriptor

覈對當前沒有數據發送或接受到:

GETtohttp://192.168.134.144:48080/api/v1/event/count

修改depth:

PUTtohttp://localhost:48082/api/v1/device/<systemspecificdeviceid>/command/<systemspecificcommandid>
PUT to http://192.168.134.144:48082/api/v1/device/5cd4ec699f8fc2000172abad/command/5cd4eaeb9f8fc2000172aba8
BODY:{"depth":"9"}

由於沒有設備,執行失敗,可經過log確認程序執行過:

dockerlogsedgex-core-command INFO: 2019/05/10 03:34:37 Issuing PUT command to: http://172.20.0.1:49977/api/v1/devices/5cd4ec699f8fc2000172abad/scandepth
ERROR: 2019/05/10 03:34:37 Put http://172.20.0.1:49977/api/v1/devices/5cd4ec699f8fc2000172abad/scandepth: dial tcp 172.20.0.1:49977: getsockopt: connection refused

10.發送數據

模擬發送數據:

POSTtohttp://192.168.134.144:48080/api/v1/event
BODY:{"device":"countcamera1","readings":[{"name":"humancount","value":"5"},{"name":"caninecount","value":"3"}]}

讀取數據:

GETtohttp://192.168.134.144:48080/api/v1/event/device/countcamera1/10
GET to http://192.168.134.144:48080/api/v1/event/count
GET to http://192.168.134.144:48080/api/v1/reading/name/humancount/10

11.註冊遠端接收客戶端

主機搭建mosquitto服務器,並監聽a/b/c主題。

POST to http://192.168.134.144:48071/api/v1/registration
{"name":"MyMQTTTopic","addressable":{"name":"MyMQTTBroker","protocol":"TCP","address":"192.168.134.144","port":1883,"publisher":"EdgeXExportPublisher","user":"wang","password":"mypass","topic":"a/b/c"},"format":"JSON","enable":true,"destination":"MQTT_TOPIC"}

此時發送的數據moquitto也會接收到相關數據。

 

參考:

1.edgex官網文檔

2.edgex-go github

3.edgex容器https://hub.docker.com/u/edgexfoundry/

4.EdgeX Foundry邊緣計算框架簡介

5.在樹莓派3b+上運行edgex 

6. https://github.com/edgexfoundry/docker-edgex-mongo  mongo容器製做

7. https://github.com/edgexfoundry/docker-edgex-volume  volume容器製做

8. EdgeX Foundry在流媒體領域中的應用 vmare中國研發中心 微信公衆號

相關文章
相關標籤/搜索