通过订阅设备数据上报Topic,应用程序可以监听设备上报的属性值和事件信息。
属性上报
设备属性上报Topic:thing/notify/$Your_ProductKey/$Your_DeviceName/property
说明 $Your_ProductKey表示设备所属产品的ProductKey,$Your_DeviceName表示设备的名称。
设备上报的数据格式:
Payload:
{
"key1":{
"value":"value1",
"time":1524448722000
},
"key2":{
"value":"value2",
"time":1524448722000
}
}
参数 | 类型 | 说明 |
---|---|---|
key | String | 上报的属性名称(属性标识符)。 |
value | Object | 上报的属性值。 |
time | Long | 属性上报时间。 |
事件上报
设备事件上报Topic:thing/notify/$Your_ProductKey/$Your_DeviceName/${tsl.event.identifier}
说明 $Your_ProductKey表示设备所属产品的ProductKey,$Your_DeviceName表示设备的名称,${tsl.event.identifier}表示设备所属产品物模型(TSL)中的事件名称。
设备上报的数据格式:
Payload:
{
"params": {
"value" : {
"key1":"value1",
"key2":"value2"
},
"time" : 1524448722000
}
}
参数 | 类型 | 说明 |
---|---|---|
params | List | 上报事件的参数。 |
value | Object | 具体的事件信息。如上示例中:
|
time | Long | 事件生成的时间戳,类型为UTC毫秒级时间。 |
完整示例
/* 订阅设备属性上报Topic,接收设备属性上报数据 */
#./mosquitto_sub --psk-identity linkedge --psk 123456aBcdef12345678123456ABCDEf -p 8883 -t thing/notify/+/+/property -v &
thing/notify/a1Mtx4p****/LightSensor/property {"MeasuredIlluminance":{"value":550,"time":1566622620054}}
thing/notify/a1Mtx4p****/LightSensor/property {"MeasuredIlluminance":{"value":600,"time":1566622650058}}
thing/notify/a1Mtx4p****/LightSensor/property {"MeasuredIlluminance":{"value":650,"time":1566622680092}}
说明 其中,mosquitto_sub和mosquitto_pub是用来订阅和发送MQTT消息的命令行工具,详细信息请参见官方文档。
原创文章,作者:网友投稿,如若转载,请注明出处:https://www.cloudads.cn/archives/34154.html