一.概述
Edgex foundry是一個Linux 基金會運營的開源邊緣計算物聯網軟件框架項目,該項目的核心是基於與硬件和操作系統完全無關的參考軟件平台建立的互操作框架,使能即插即用的組件生態系統,統一市場,加速物聯網方案的部署。EdgeX Foundry 使有意參與的各方在開放與互操作的物聯網方案中自由協作,無論他們是使用公開標准或私有方案。
EdgeX Foundry微服務集合構成了四個微服務層及兩個增強的基礎系統服務,四個微服務層包含了從物理域數據采集到信息域數據處理等一系列的服務,另外兩個基礎系統服務為該四個服務層提供支撐服務。
四個微服務層從物理層到應用層依次為:設備服務層(device service),核心服務層(core service),支持服務層(supporting service),開放服務層(export service)。
兩個增強基礎服務:security和system Management。
在edgex中區分南北向:South Side和North Side:
South Side:All IoT 設備、傳感器、執行器等數據的來源端。
North Side:雲端(the Cloud),數據在這里存儲、匯聚、分析、整合等。
二.Core Services
核心服務層包含下列組件:
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也會接收到相關數據。
參考:
3.edgex容器https://hub.docker.com/u/edgexfoundry/
6. https://github.com/edgexfoundry/docker-edgex-mongo mongo容器制作
7. https://github.com/edgexfoundry/docker-edgex-volume volume容器制作
8. EdgeX Foundry在流媒體領域中的應用 vmare中國研發中心 微信公眾號
9. API參考 restful https://docs.edgexfoundry.org/1.2/api/core/Ch-APICoreCommand/