Skip to content

订阅指定设备属性上报

更新时间:

该Topic用于订阅指定设备属性上报消息。

前提

Topic

/device/{productId}/{deviceId}/message/property/report

订阅消息

  1. 生成随机13位数
js
randomNum = Math.random().toFixed(13).slice(-13)
randomNum = Math.random().toFixed(13).slice(-13)
  1. 发送消息内容到 WebSocket
json
{
  "type": "sub",
  "topic": "/device/产品id/设备id/message/property/report",
  "parameter": {},
  "id": "request-id" + randomNum
}
{
  "type": "sub",
  "topic": "/device/产品id/设备id/message/property/report",
  "parameter": {},
  "id": "request-id" + randomNum
}

订阅示例

json
{
    "type": "sub",
    "topic": "/device/api-test/api-test-device1/message/property/report",
    "parameter": {},
    "id": "request-id"
}
{
    "type": "sub",
    "topic": "/device/api-test/api-test-device1/message/property/report",
    "parameter": {},
    "id": "request-id"
}

消息推送格式

成功订阅指定设备属性上报消息后,当设备上报属性时,平台会将属性上报消息实时推送到 WebSocket ,消息推送格式如下:

名称类型必选约束说明
» requestIdstringtruenone订阅ID
» topicstringtruenone订阅Topic
» payload[object]truenone消息负载
»» headers[object]truenone消息头
»»» deviceNamestringtruenone设备名称
»»» productNamestringtruenone产品名称
»»» productId[object]truenone产品ID
»»» _uidstringfalsenone平台统一生成uid
»»» creatorIdstringfalsenone创建者ID
»»» traceparentstringfalsenone链路追踪父ID
»» deviceIdstringtruenone设备ID
»» timestamplongtruenone时间戳
»» properties[object]falsenone物模型属性
»» messageTypestringtruenone消息类型
» typestringtruenone类型

消息推送示例

json
{
    "requestId": "request-id-1691046529730",
    "topic": "/device/api-test/api-test-device1/message/property/report",
    "payload": {
        "headers": {
            "deviceName": "api测试设备1",
            "productName": "api测试",
            "productId": "api-test",
            "_uid": "E4m6Rm4b8TTf36Qyc61lgCaiS3kwH5bU",
            "creatorId": "1199596756811550720",
            "traceparent": "00-10b5b93161052499e75cc2df3ea1ee11-2dbcb0246cd3f643-01"
        },
        "deviceId": "api-test-device1",
        "timestamp": 1691047325210,
        "properties": {    //上报属性
            "Color": 67
        },
        "messageType": "REPORT_PROPERTY"
    },
    "type": "result"
}
{
    "requestId": "request-id-1691046529730",
    "topic": "/device/api-test/api-test-device1/message/property/report",
    "payload": {
        "headers": {
            "deviceName": "api测试设备1",
            "productName": "api测试",
            "productId": "api-test",
            "_uid": "E4m6Rm4b8TTf36Qyc61lgCaiS3kwH5bU",
            "creatorId": "1199596756811550720",
            "traceparent": "00-10b5b93161052499e75cc2df3ea1ee11-2dbcb0246cd3f643-01"
        },
        "deviceId": "api-test-device1",
        "timestamp": 1691047325210,
        "properties": {    //上报属性
            "Color": 67
        },
        "messageType": "REPORT_PROPERTY"
    },
    "type": "result"
}