edgex-foundry框架下的应用开发

edgex-foundry架构时一中微服务架构,通过docker封装程很多小的微服务,各个微服务之间是通过restful api的形式进行通讯,

在edgex-foundry下的开发主要在device server、support server、export server上开发。

开发时应该做一下几点:

一、在edgex架构中定义自己的信息

1.edgex :采集设备数据之前需要了解到的设备的相关信息,向设备发送的相关命令

2.Addressables :通过rest api设置一些设备的物理地址,device server的ip地址 ,端口号等信息

POST to http://localhost:48081/api/v1/addressable

BODY: {"name":"camera1 address","protocol":"HTTP","address":"172.17.0.1","port":49999,"path":"/camera1","publisher":"none","user":"none","password":"none","topic":"none"}

3.value description:主要时对某一个值的描述

POST to http://localhost:48080/api/v1/valuedescriptor//注意value description存储到core data数据库中,对数据提供了上下文和单位

BODY: {"name":"humancount",//unique

"description":"people count", "min":"0","max":"100","type":"I","uomLabel":"count","defaultValue":"0","formatting":"%s","labels":["count","humans"]}

二、定义你的设备

Adding a Device Profile

POST to http://localhost:48081/api/v1/deviceprofile/uploadfile

FORM-DATA:

key: “file”

value: EdgeX_CameraMonitorProfile.yml

device profile中的内容格式:

name: "camera monitor profile"

manufacturer: "Dell"

model: "Cam12345"

labels:

- "camera"

description: "Human and canine camera monitor profile"

commands:

-

name: People

get:

path: "/api/v1/devices/{deviceId}/peoplecount"//addressable中的url拼出路径进行访问

responses:

-

code: "200"

description: "Number of people on camera"

expectedValues: ["humancount"] //返回的json中的key值。

-

code: "503"

description: "service unavailable"

expectedValues: ["cameraerror"]

 

device profile中定义了如何和设备和传感器进行通讯。定义了一些命令去控制设备。

三、注册你的device service

向meta data中发送post请求

POST to http://localhost:48081/api/v1/deviceservice

BODY: {

"name":"camera control device service", //unique

"description":"Manage human and dog counting cameras",

"labels":["camera","counter"],

"adminState":"unlocked",//locked代表不响应任何command请求和发送device data

"operatingState":"enabled", //不能被其他的服务设置,是该服务操作状态的一个标志

"addressable":{"name":"camera control"}

}

四、创建设备

提供设备必需在meta data server中将device profile、deivce service、addressable联系起来。

通过apI的形式:

POST to http://localhost:48081/api/v1/device

BODY: {"name":"countcamera1",

"description":"human and dog counting camera #1",

"adminState":"unlocked",

"operatingState":"enabled",

"addressable":{"name":"camera1 address"},//addressable中的name

"labels":["camera","counter"],

"location":"",

"service":{"name":"camera control device service"},//device service中的name

"profile":{"name":"camera monitor profile"}}//device profile中的name

 

GET to http://localhost:48081/api/v1/deviceservice得到所有的deviceservice的信息

GET to http://localhost:48081/api/v1/deviceservice/label/camera得到label为camera的device service的信息

五、调用命令

列出设备的命令:

GET to http://localhost:48082/api/v1/device/name/countcamera1列出名字为countcamera1的设备的信息

{

"id": "5c6bcc319f8fc20001995995",

"name": "JC.RR5.NAE9.ConfRoom.Padre.Island01",

"adminState": "UNLOCKED",

"operatingState": "ENABLED",

"lastConnected": 1550713108339,

"lastReported": 0,

"labels": [

"thermostat",

"industrial"

],

"location": null,

"commands": [

{

"created": 1550568497699,

"modified": 0,

"origin": 0,

"id": "5c6bcc319f8fc2000199598d",

"name": "CurrentTemperature",

"get": {

"path": "/api/v1/device/{deviceId}/CurrentTemperature",

"responses": [

{

"code": "200",

"description": null,

"expectedValues": [

"AnalogInput_3000290"

]

},

{

"code": "503",

"description": "service unavailable",

"expectedValues": []

}

],

"url": "http://edgex-core-command:48082/api/v1/device/5c6bcc319f8fc20001995995/command/5c6bcc319f8fc2000199598d"

//调用device command的接口/deivce/id/command/id

},

},

]

}

查看一个值的描述:

GET to http://localhost:48080/api/v1/valuedescriptor//注意 这个值存储在core data中

调用command

首先查看设备的命令列表得到相关的url:然后就可以调用

PUT to http://localhost:48082/api/v1/device//command/

BODY: {"depth":"9"}

 

六 、发送事件和读取数据

设备主动发送事件数据:

首先数据会以event的形式上报。通过对一个值的value decription(通过api设定)来读取events。多个值通过key/value对组合成一个event进行发送。

POST to http://localhost:48080/api/v1/event

BODY: {"device":"countcamera1","readings":[{"name":"humancount","value":"5"},{"name":"caninecount","value":"3"}]}

也可以在每个value中添加一个时间戳如下

BODY: {"device":"countcamera1","origin":1471806386919, "readings":[{"name":"humancount","value":"1","origin":1471806386919},{"name":"caninecount","value":"0","origin":1471806386919}]}

采集存到数据库中的设备的数据:

得到event的数量

GET to http://localhost:48080/api/v1/event/count

获得countcameral设备的10条信息

GET to http://localhost:48080/api/v1/event/device/countcamera1/10

获得countcameral设备中关于humancount的10条数据

GET to http://localhost:48080/api/v1/reading/name/humancount/10

七、export 你设备的数据到云

rule engine会自动的注册为export server,或将所有的过滤后的数据都export到云端

如果想注册一个新的设备来接受core data中的数据则要注册export service

首先要清楚注册的export service是以什么形式向数据发出去让云端的service接收,http or mqtt

下面注册个matt的export service

POST to http://localhost:48071/api/v1/registration

BODY: {"name":"MyMQTTTopic",

"addressable:{"name":"MyMQTTBroker","protocol":"TCP","address":"tcp://m10.cloudmqtt.com","port":15421,"publisher":"EdgeXExportPublisher","user":"hukfgtoh","password":"mypass","topic":"EdgeXDataTopic"},

"format":"JSON",

"encryption":{"encryptionAlgorithm":"AES","encryptionKey":"123","initializingVector":"123"},

"enable":true,

"destination":"MQTT_TOPIC"}

具体的api文档查看

https://docs.edgexfoundry.org/index.html

 

你可能感兴趣的:(java类,docker,架构)