Skip to content

订阅指定设备离线消息

更新时间:

该Topic用于订阅指定设备离线消息。

前提

  • 设备处于离线状态。

  • 需要设备上线,连接详情参见设备上线

Topic

/device/{productId}/{deviceId}/offline

订阅消息

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

订阅示例

json
{
    "type": "sub",
    "topic": "/device/api-test/api-test-device1/offline",
    "parameter": {},
    "id": "request-id" + randomNum
}
{
    "type": "sub",
    "topic": "/device/api-test/api-test-device1/offline",
    "parameter": {},
    "id": "request-id" + randomNum
}

消息推送格式

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

名称类型必选约束说明
» requestIdstringtruenone订阅ID
» topicstringtruenone订阅Topic
» payload[object]truenone消息负载
»» headers[object]truenone消息头
»»» serverIdstringtruenone服务ID
»»» deviceNamestringtruenone设备名称
»»» productNamestringtruenone产品名称
»»» productIdstringtruenone产品ID
»»» connectTimelongtruenone设备上线时间
»»» _uidstringtruenone平台统一生成uid
»»» creatorIdstringtruenone创建者ID
»» deviceIdstringtruenone设备ID
»» timestamplongtruenone时间戳
»» messageTypestringtruenone消息类型,固定为OFFLINE
» typestringtruenone类型

消息推送示例

json
{
    "requestId": "request-id-1691066099045",
    "topic": "/device/api-test/api-test-device1/offline",
    "payload": {
        "headers": {
            "serverId": "Himalaya-platform:9101",
            "deviceName": "api测试设备1",
            "productName": "api测试",
            "connectTime": 1691066106875,
            "from": "session",
            "productId": "api-test",
            "_uid": "VYm7ZRAcRJCWIPD_kP4gZ-NPHK3-TPi6",
            "creatorId": "1199596756811550720"
        },
        "deviceId": "api-test-device1",
        "timestamp": 1691066109980,
        "messageType": "OFFLINE"
    },
  "type": "result"
}
{
    "requestId": "request-id-1691066099045",
    "topic": "/device/api-test/api-test-device1/offline",
    "payload": {
        "headers": {
            "serverId": "Himalaya-platform:9101",
            "deviceName": "api测试设备1",
            "productName": "api测试",
            "connectTime": 1691066106875,
            "from": "session",
            "productId": "api-test",
            "_uid": "VYm7ZRAcRJCWIPD_kP4gZ-NPHK3-TPi6",
            "creatorId": "1199596756811550720"
        },
        "deviceId": "api-test-device1",
        "timestamp": 1691066109980,
        "messageType": "OFFLINE"
    },
  "type": "result"
}