阿里雲IoT物模型-屬性,服務,事件通訊的topic和payload詳解

wongxmig發表於2018-09-12

0.阿里雲IoT物模型

 
物模型定義了產品的屬性、服務、事件通訊協議,IoT裝置和雲端需要按約定規則通訊,才能實現物模型轉化。
 
 

1.裝置屬性通訊

1.1 裝置上報屬性

裝置上報pubTopic

/sys/{productKey}/{deviceName}/thing/event/property/post
裝置上報payload格式
{
“id”: 3536123,
“version”: “1.0”,
“params”: {
“屬性key1”: “屬性value1”,
“屬性key2”: “屬性value2”
},
“method”: “thing.event.property.post”
}
 

IoT雲端響應replyTopic

/sys/{productKey}/{deviceName}/thing/event/property/post_reply
雲端響應payload格式
{
“id”: 3536123,
“code”: 200,
“data”: {}
}
 
 

1.2 雲端設定裝置屬性

裝置訂閱subTopic

/sys/{productKey}/{deviceName}/thing/service/property/set
IoT雲端下行的payload格式
{
“id”: 3536123,
“version”: “1.0”,
“params”: {
“屬性key1”: “屬性value1”,
“屬性key2”: “屬性value2”
},
“method”: “thing.service.property.set”
}
 
 

裝置響應replyTopic

/sys/{productKey}/{deviceName}/thing/service/property/set_reply
裝置響應payload格式
{
“id”: 3536123,
“code”: 200,
“data”: {}
}
 
 

1.3 雲端獲取裝置屬性

裝置訂閱subTopic

/sys/{productKey}/{deviceName}/thing/service/property/get
IoT雲端下行的payload格式
{
“id”: 3536123,
“version”: “1.0”,
“params”: [
“屬性key1”,
“屬性key2”
],
“method”: “thing.service.property.get”
}
 
 

裝置響應replyTopic

/sys/{productKey}/{deviceName}/thing/service/property/get_reply
裝置響應payload格式
{
“id”: 3536123,
“code”: 200,
“data”: {
“屬性key1”: “屬性value1”,
“屬性key2”: “屬性value2”
}
}
 
 
 

2.裝置服務呼叫

2.1 服務的非同步呼叫

裝置訂閱subTopic

注意:服務訂閱Topic這裡不支援+萬用字元
/sys/{productKey}/{deviceName}/thing/service/{tsl.service.identifier}
或者訂閱指定service
/sys/{productKey}/{deviceName}/thing/service/{tsl.service.identifier}
IoT雲端下行的payload格式
{
“id”: 3536123,
“version”: “1.0”,
“params”: {
“入參key1”: “入參value1”,
“入參key2”: “入參value2”
},
“method”: “thing.service.{tsl.service.identifier}”
}
 
 

裝置響應replyTopic

/sys/{productKey}/{deviceName}/thing/service/{tsl.service.identifier}_reply
裝置響應payload格式
{
“id”: 3536123,
“code”: 200,
“data”: {
“出參key1”: “出參value1”,
“出參key2”: “出參value2”
}
}
 

2.2 服務的同步呼叫

 

裝置訂閱subTopic

注意:服務同步呼叫API是InvokeThingService
/sys/${productKey}/${deviceName}/rrpc/request/+
IoT雲端下行的payload格式
{
“id”: 3536123,
“version”: “1.0”,
“params”: {
“入參key1”: “入參value1”,
“入參key2”: “入參value2”
},
“method”: “thing.service.{tsl.service.identifier}”
}
 
 

裝置響應replyTopic

/sys/${productKey}/${deviceName}/rrpc/response/request的訊息Id
 
裝置響應payload格式
{
“id”: 3536123,
“code”: 200,
“data”: {
“出參key1”: “出參value1”,
“出參key2”: “出參value2”
}
}
 
 

3.裝置事件上報

3.1 事件上報

裝置上報pubTopic

/sys/{productKey}/{deviceName}/thing/event/{tsl.event.identifier}/post
裝置上報payload格式
{
“id”: 3536123,
“version”: “1.0”,
“params”: {
“入參key1”: “入參value1”,
“入參key2”: “入參value2”
},
“method”: “thing.event.{tsl.event.identifier}.post”
}
 
 

IoT雲端響應replyTopic

/sys/{productKey}/{deviceName}/thing/event/{tsl.event.identifier}/post_reply
雲端響應payload格式
{
“id”: 3536123,
“code”: 200,
“data”: {}
}


相關文章