跳至主要內容

物联网平台通用数据协议

技术中心大约 2 分钟

物联网平台通用数据协议

该数据协议为MQTT+JSON,协议仅规定了设备与平台之间的通讯格式要求与类型,并未限制设备本身属性或可采集的属性信息。

功能设备权限描述
属性上报发布设备属性上报
属性上报响应订阅云端响应属性上报
属性设置订阅设备属性设置
属性设置响应发布设备属性设置项目
事件上报发布设备事件上报
事件上报响应订阅云端响应事件上报
服务调用订阅设备服务调用
服务调用响应发布设备端响应服务调用

设备对接流程:

属性上报

请求主题:

/sys/${productKey}/${deviceKey}/thing/event/property/post

请求结构:

{
    "id": "123",
    "version": "1.0",
    "sys":{
        "ack":0
    },
    "params": {
        "Power": {
            "value": "on",
            "time": 1524448722000
        },
        "WF": {
            "value": 23.6,
            "time": 1524448722000
        }
    },
    "method": "thing.event.property.post"
}

响应主题:

/sys/${productKey}/${deviceKey}/thing/event/property/post_reply

响应结构:

  • 成功
{
    "code": 200,
    "data": {},
    "id": "123",
    "message": "success",
    "method": "thing.event.property.post",
    "version": "1.0"
}
  • 失败

{
    "code": 6813,
    "data": {},
    "id": "123",
    "message": "The format of result is error!",
    "method": "thing.event.property.post",
    "version": "1.0"
}

属性设置

请求主题:

/sys/${productKey}/${deviceKey}/thing/service/property/set

请求结构:

{
    "id": "123",
    "version": "1.0",
    "params": {
        "temperature": "30.5"
    },
    "method": "thing.service.property.set"
}

响应主题:

/sys/${productKey}/${deviceKey}/thing/event/property/set_reply

响应数据格式:

注意: id值为32bit

  • 成功
{
    "code": 200,
    "data": {},
    "id": "123",
    "message": "success",
    "version": "1.0"
}
  • 失败
{
    "code": 9201,
    "data": {},
    "id": "123",
    "message": "device offLine",
    "version": "1.0"
}

事件上报

多模块说明

物模型支持自定义多模块,当存在多模块时需要填入${tsl.functionBlockId},并采用:分割。如果为默认模块则不用加入模块标识,仅填写事件表示即可。

请求主题:

/sys/${productKey}/${deviceKey}/thing/event/${tsl.functionBlockId}:${tsl.event.identifier}/post

请求结构:

{
    "id": "123",
    "version": "1.0",
    "sys":{
        "ack":0
    },
    "params": {
        "value": {
            "Power": "on",
            "WF": "2"
        },
        "time": 1524448722000
    },
    "method": "thing.event.${tsl.event.identifier}.post"
}

响应主题:

/sys/${productKey}/${deviceKey}/thing/event/${tsl.functionBlockId}:${tsl.event.identifier}/post_reply

响应数据格式:

注意: id值为32bit

  • 成功
{
    "code": 200,
    "data": {},
    "id": "123",
    "message": "success",
    "version": "1.0"
}
  • 失败
{
    "code": 9201,
    "data": {},
    "id": "123",
    "message": "device offLine",
    "version": "1.0"
}

服务调用

请求Topic:

/sys/${productKey}/${deviceKey}/thing/service/${tsl.functionBlockId}:${tsl.service.identifier}

请求结构:

{
    "id": "123",
    "version": "1.0",
    "params": {
        "Power": "on",
        "WF": "2"
    },
    "method": "thing.service.${tsl.service.identifier}"
}

响应主题:

/sys/${productKey}/${deviceKey}/thing/service/${tsl.functionBlockId}:${tsl.service.identifier}_reply

响应数据格式:

  • 成功
{
    "code": 200,
    "data": {},
    "id": "123",
    "message": "success",
    "version": "1.0"
}
  • 失败
{
    "code": 9201,
    "data": {},
    "id": "123",
    "message": "device offLine",
    "version": "1.0"
}