长链接服务
更新时间:2018-05-25 09:27:16
提供基于用户维度的长链接通道服务,包括连接通道的绑定、解绑和消息接收。通过长链接服务客户端可以轻松的实现设备实时变更消息的接收。
用户中心长连接
绑定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"
}
解绑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"
}
设备消息下行到APP
mqtt消息。
设备属性变更推送
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表示当前状态的开始时间;