子设备数据云边交互方式-v2
更新时间:2022-10-26
子设备数据云边交互方式
本节对子设备数据云边交互协议做一些补充。 驱动接收真实设备的数据,并将数据同步至broker。通过订阅broker的topic,可以看到子设备数据的云边交互格式。
子设备上报在离线状态
- thing/{deviceProductKey}/{deviceName}/lifecycle/post
该主题当中的消息为驱动采集设备上传到云端的在离线状态数据
Plain Text
1{
2 "kind": "thing.lifecycle.post",
3 "meta": {
4 "accessTemplate": "access-template-test",
5 "device": "device-test-1",
6 "deviceProduct": "product-test",
7 "node": "node-test",
8 "nodeProduct": "BIE-Product"
9 },
10 "content": {
11 "blink": {
12 "reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
13 "method": "thing.lifecycle.post",
14 "version": "1.0",
15 "timestamp": 1659003513995,
16 "params": {
17 "online_state": true
18 }
19 }
20 }
21}
子设备定期上报测点数据
- thing/{deviceProductKey}/{deviceName}/property/post
该主题当中的消息为驱动采集设备上传到云端的测点数据
Plain Text
1{
2 "kind": "deviceReport",
3 "meta": {
4 "accessTemplate": "access-template-test",
5 "device": "device-test-1",
6 "deviceProduct": "product-test",
7 "node": "node-test",
8 "nodeProduct": "BIE-Product"
9 },
10 "content": {
11 "blink": {
12 "reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
13 "method": "thing.property.post",
14 "version": "1.0",
15 "timestamp": 1659003513995,
16 "properties": {
17 "high-temperature-alarm": false,
18 "high-temperature-threshold": 324,
19 "humidity": 74.66774,
20 "switch": true,
21 "temperature": 315.88257
22 }
23 }
24 }
25}
子设备上报事件数据
- thing/{deviceProductKey}/{deviceName}/event/post
该主题当中的消息为驱动采集设备上传到云端的事件数据
Plain Text
1{
2 "kind": "thing.event.post",
3 "meta": {
4 "accessTemplate": "access-template-test",
5 "device": "device-test-1",
6 "deviceProduct": "product-test",
7 "node": "node-test",
8 "nodeProduct": "BIE-Product"
9 },
10 "content": {
11 "blink": {
12 "reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
13 "method": "thing.event.post",
14 "version": "1.0",
15 "timestamp": 1659003513995,
16 "events": {
17 "fire": {
18 "eventId": "1646209549103-N001L01.003",
19 "eventType": "FIRE",
20 "event": "FIRE",
21 "videoType": "FIRE",
22 "channel": "ir-r100-01",
23 "deviceName": "ir-ganwen-001",
24 "machineNumber": "N001L01.001"
25 },
26 "short_circuit": {
27 "xxxx": 30
28 },
29 "open_circuit": {
30 "xxxx": 0
31 }
32 }
33 }
34 }
35}
驱动接收来自云端的变更(置数)
- thing/{deviceProductKey}/{deviceName}/property/invoke
云端对边缘子设备的置数消息,会发送消息到此主题。消息格式如下:
Plain Text
1{
2 "kind": "deviceDelta",
3 "meta": {
4 "device": "device-test-1",
5 "deviceProduct": "product-test",
6 "node": "node-test",
7 "nodeProduct": "BIE-Product"
8 },
9 "content": {
10 "blink": {
11 "reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
12 "method": "thing.property.invoke",
13 "version": "1.0",
14 "timestamp": 1659003513995,
15 "properties": {
16 "temperature": 27.1,
17 "humidity": 22,
18 "switch": true
19 }
20 }
21 }
22}
驱动订阅云端对子设备的置数请求,将会发起置数操作。
驱动接收来自云端的事件(召测)
- thing/{deviceProductKey}/{deviceName}/property/get
云端对边缘子设备的召测请求,会发送消息到此主题。消息格式如下:
Plain Text
1{
2 "kind": "thing.property.get",
3 "meta": {
4 "accessTemplate": "access-template-test",
5 "device": "device-test-1",
6 "deviceProduct": "product-test",
7 "node": "node-test",
8 "nodeProduct": "BIE-Product"
9 },
10 "content": {
11 "blink": {
12 "reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
13 "method": "thing.property.get",
14 "version": "1.0",
15 "timestamp": 1659003513995,
16 "properties": [
17 "temperature",
18 "humidity",
19 "switch"
20 ]
21 }
22 }
23}
驱动订阅云端对子设备的召测请求,将会发起数据采集并上报的操作。同步会在thing/{deviceProductKey}/{deviceName}/property/post
这个topic当中订阅到上报到云端的数据,格式如下:
Plain Text
1{
2 "kind": "deviceReport",
3 "meta": {
4 "accessTemplate": "access-template-test",
5 "device": "device-test-1",
6 "deviceProduct": "product-test",
7 "node": "node-test",
8 "nodeProduct": "BIE-Product"
9 },
10 "content": {
11 "blink": {
12 "reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
13 "method": "thing.property.post",
14 "version": "1.0",
15 "timestamp": 1659003513995,
16 "properties": {
17 "high-temperature-alarm": false,
18 "high-temperature-threshold": 324,
19 "humidity": 74.66774,
20 "switch": true,
21 "temperature": 315.88257
22 }
23 }
24 }
25}
驱动接收来自云端的自定义格式消息(事件下发)
- thing/{deviceProductKey}/{deviceName}/raw/c2d
云端对边缘子设备的自定义格式消息(事件下发),会发送消息到此主题。消息格式如下:
Plain Text
1{
2 "kind": "deviceEvent",
3 "meta": {
4 "device": "device-test-1"
5 },
6 "content": {
7 "type": "",
8 "payload": {}
9 }
10}
content中的payload为自定义格式消息内容
边缘侧请求设备数据
- $baetyl/device/{device-name}/get
- $baetyl/device/{device-name}/getResponse
向主题$baetyl/device/{device-name}/get
发送任意消息,比如{'hello':'world'}
,或者123
,驱动都会主动采集一次设备数据,并将采集到是数据发送到主题$baetyl/device/{device-name}/getResponse
,数据格式如下:
Plain Text
1{
2 "kind":"response",
3 "meta":{
4 "device":"mod-test-1"
5 },
6 "content":{
7 "name":"mod-test-1",
8 "report":{
9 "high-temperature-alarm":true,
10 "high-temperature-threshold":324,
11 "humidity":13.870032,
12 "status":"online",
13 "switch":true,
14 "temperature":370.4124
15 },
16 "desire":{
17 "high-temperature-threshold":370
18 }
19 }
20}