提供基于用户维度的长连接通道服务,包括连接通道的绑定、解绑和消息接收。通过长连接服务客户端可以轻松的实现设备实时变更消息的接收。

用户中心长连接

设备消息下行到App

绑定MQTT消息通道

上行,绑定 iotToken对应的用户 和 clientId指定的mqtt通道。

TOPIC: /sys/${productKey}/${deviceName}/app/up/account/bind
REPLY TOPIC:/sys/${productKey}/${deviceName}/app/down/account/bind_reply

request:
{
  "id": "msgid1",
  "version": "1.0",
  "request": {
    "clientId": "mqttusername1234"
  },
  "params": {
    "iotToken": "iot_token123"
  }
}

response:
{
    "id":"msgid1",
    "code":200,
    "message":"success"
}
        
说明 通常情况下,开发者不需要主动调用这个接口,长连接 SDK 中已经封装了本接口的实现。

解绑MQTT消息通道

上行,解绑 clientId指定的mqtt通道 及此通道对应的用户。

TOPIC: /sys/${productKey}/${deviceName}/app/up/account/unbind
REPLY TOPIC:/sys/${productKey}/${deviceName}/app/down/account/unbind_reply

request:
{
  "id": "msgid2",
  "version": "1.0",
  "request": {
    "clientId": "mqttusername1234"
  },
  "params": {
  }
}

response:
{
    "id":"msgid2",
    "code":200,
    "message":"success"
}
        
说明 通常情况下,开发者不需要主动调用这个接口,长连接 SDK 中已经封装了本接口的实现。

设备属性变更推送

TOPIC: /sys/${productKey}/${deviceName}/app/down/thing/properties

MESSAGE:
{
  "id": "msgid3",
  "version": "1.0",
  "params": {
          "iotId":"0300MSKL03667c544f69342a74Sv4Za4",
          "productKey":"X5eCzh6fEH7",
          "deviceName":"5gJtxDVeGAkaEztpisjX",
          "items":{
              "temperature":{
                  "time":1510292697471,
                  "value":30
              },
              "meterReadingMonth":{
                  "time":1510292697470,
                  "value":715665571
              },
              "alarm":{
                  "time":1510292697470,
                  "value":"normal"
              }
          }
    },
  "method":""
}
// 其中,temperature为属性唯一标识符; time为设备属性上报时间,value为设备属性值;value数据规范可参考TSL描述。 

设备事件变更推送

TOPIC: /sys/${productKey}/${deviceName}/app/down/thing/events

MESSAGE:
{
  "id": "msgid4",
  "version": "1.0",
  "params":{
      "identifier":"BrokenInfo"
      "name":"损坏率上报",
      "type":"info",
      "iotId":"4z819VQHk6VSLmmBJfrf00107ee200",
      "productKey":"X5eCzh6fEH7",
      "deviceName":"5gJtxDVeGAkaEztpisjX",
      "value":{
        "Power":"on"
        "structParam":{
                "param1":"abc",
                "param2":123
            }
       },
       "time":1510799670074
   }
   "method":"thing.events"
}
// 其中,identifier为事件唯一标识符,Power为参数唯一标识符的示例,on为Ponwer对应的值,规范详见物的TSL描述;time为事件上报的时间戳;type为事件类型,有info,error,block等类型。      

设备连接状态变更推送

TOPIC: /sys/${productKey}/${deviceName}/app/down/thing/status

MESSAGE:
{
  "id": "msgid4",
  "version": "1.0",
  "params":{
        "iotId":"0300MSKL03667c544f69342a74Sv4Za4",
        "productKey":"X5eCzh6fEH7",
        "deviceName":"5gJtxDVeGAkaEztpisjX",
        "status":{
             "time":1510292697471,
             "value":"0"
         }
  }
  "method":"thing.status"  //0:未激活;1:上线;3:离线;8:禁用; 
}
// 其中,status表示设备生命周期,目前有以下几个状态,0:未激活;1:上线;3:离线;8:禁用;time表示当前状态的开始时间。

添加子设备结果推送到移动客户端

TOPIC: /sys/{productKey}/{deviceName}/app/down/thing/topo/add/status

{
    "id":"msgId1",
    "version":"1.0",
    "param":{
        "status":0, //0 添加topo成功,1 子设备注册,设备已被其它网关绑定, 2 子设备注册,注册失败
        "subIotId":"xxx",
        "subProductKey":"xxx",
        "subDeviceName":"xxx",
        "oldGwIotId":"xxx",
        "oldGwProductKey":"xxx",
        "oldGwDeviceName":"xxx",
        "newGwIotId":"xxx",
        "newGwProductKey":"xxx",
        "newGwDeviceName":"xxx"
    },
    "method":"thing.topo.add.status"
}

固件升级进度推送到移动客户端

OPIC: /sys/{productKey}/{deviceName}/app/down/ota/device/forward

{
    "id": "123456790123",
    "version": "1.0",
    "params": {
        "iotId": "",
        "srcVersion": "", //最近一次升级源版本
        "destVersion": "", //最近一次升级目标版本
        "step": 1, //升级进度百分比及错误码
        "desc": "", //升级进度错误码对应信息描述
        "upgradeStatus": 1 //0:待升级或待确认,1:升级中,2:升级异常,3:升级失败,4:升级完成。
    },
    "method":"ota.device.forward"
}