子设备数据云边交互方式-v2
更新时间:2022-10-26
子设备数据云边交互方式
本节对子设备数据云边交互协议做一些补充。 驱动接收真实设备的数据,并将数据同步至broker。通过订阅broker的topic,可以看到子设备数据的云边交互格式。
子设备上报在离线状态
- thing/{deviceProductKey}/{deviceName}/lifecycle/post
该主题当中的消息为驱动采集设备上传到云端的在离线状态数据
{
"kind": "thing.lifecycle.post",
"meta": {
"accessTemplate": "access-template-test",
"device": "device-test-1",
"deviceProduct": "product-test",
"node": "node-test",
"nodeProduct": "BIE-Product"
},
"content": {
"blink": {
"reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
"method": "thing.lifecycle.post",
"version": "1.0",
"timestamp": 1659003513995,
"params": {
"online_state": true
}
}
}
}
子设备定期上报测点数据
- thing/{deviceProductKey}/{deviceName}/property/post
该主题当中的消息为驱动采集设备上传到云端的测点数据
{
"kind": "deviceReport",
"meta": {
"accessTemplate": "access-template-test",
"device": "device-test-1",
"deviceProduct": "product-test",
"node": "node-test",
"nodeProduct": "BIE-Product"
},
"content": {
"blink": {
"reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
"method": "thing.property.post",
"version": "1.0",
"timestamp": 1659003513995,
"properties": {
"high-temperature-alarm": false,
"high-temperature-threshold": 324,
"humidity": 74.66774,
"switch": true,
"temperature": 315.88257
}
}
}
}
子设备上报事件数据
- thing/{deviceProductKey}/{deviceName}/event/post
该主题当中的消息为驱动采集设备上传到云端的事件数据
{
"kind": "thing.event.post",
"meta": {
"accessTemplate": "access-template-test",
"device": "device-test-1",
"deviceProduct": "product-test",
"node": "node-test",
"nodeProduct": "BIE-Product"
},
"content": {
"blink": {
"reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
"method": "thing.event.post",
"version": "1.0",
"timestamp": 1659003513995,
"events": {
"fire": {
"eventId": "1646209549103-N001L01.003",
"eventType": "FIRE",
"event": "FIRE",
"videoType": "FIRE",
"channel": "ir-r100-01",
"deviceName": "ir-ganwen-001",
"machineNumber": "N001L01.001"
},
"short_circuit": {
"xxxx": 30
},
"open_circuit": {
"xxxx": 0
}
}
}
}
}
驱动接收来自云端的变更(置数)
- thing/{deviceProductKey}/{deviceName}/property/invoke
云端对边缘子设备的置数消息,会发送消息到此主题。消息格式如下:
{
"kind": "deviceDelta",
"meta": {
"device": "device-test-1",
"deviceProduct": "product-test",
"node": "node-test",
"nodeProduct": "BIE-Product"
},
"content": {
"blink": {
"reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
"method": "thing.property.invoke",
"version": "1.0",
"timestamp": 1659003513995,
"properties": {
"temperature": 27.1,
"humidity": 22,
"switch": true
}
}
}
}
驱动订阅云端对子设备的置数请求,将会发起置数操作。
驱动接收来自云端的事件(召测)
- thing/{deviceProductKey}/{deviceName}/property/get
云端对边缘子设备的召测请求,会发送消息到此主题。消息格式如下:
{
"kind": "thing.property.get",
"meta": {
"accessTemplate": "access-template-test",
"device": "device-test-1",
"deviceProduct": "product-test",
"node": "node-test",
"nodeProduct": "BIE-Product"
},
"content": {
"blink": {
"reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
"method": "thing.property.get",
"version": "1.0",
"timestamp": 1659003513995,
"properties": [
"temperature",
"humidity",
"switch"
]
}
}
}
驱动订阅云端对子设备的召测请求,将会发起数据采集并上报的操作。同步会在thing/{deviceProductKey}/{deviceName}/property/post
这个topic当中订阅到上报到云端的数据,格式如下:
{
"kind": "deviceReport",
"meta": {
"accessTemplate": "access-template-test",
"device": "device-test-1",
"deviceProduct": "product-test",
"node": "node-test",
"nodeProduct": "BIE-Product"
},
"content": {
"blink": {
"reqId": "033cc79a-6adf-4d40-b5a1-3ff33693f19c",
"method": "thing.property.post",
"version": "1.0",
"timestamp": 1659003513995,
"properties": {
"high-temperature-alarm": false,
"high-temperature-threshold": 324,
"humidity": 74.66774,
"switch": true,
"temperature": 315.88257
}
}
}
}
驱动接收来自云端的自定义格式消息(事件下发)
- thing/{deviceProductKey}/{deviceName}/raw/c2d
云端对边缘子设备的自定义格式消息(事件下发),会发送消息到此主题。消息格式如下:
{
"kind": "deviceEvent",
"meta": {
"device": "device-test-1"
},
"content": {
"type": "",
"payload": {}
}
}
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
,数据格式如下:
{
"kind":"response",
"meta":{
"device":"mod-test-1"
},
"content":{
"name":"mod-test-1",
"report":{
"high-temperature-alarm":true,
"high-temperature-threshold":324,
"humidity":13.870032,
"status":"online",
"switch":true,
"temperature":370.4124
},
"desire":{
"high-temperature-threshold":370
}
}
}