# 数据格式

# 1. 公共参数

  • 通用数据格式:
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx",        //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "xxxx",         //业务标识
    "data": {...}               //业务数据
}
  • 参数说明:

参数

类型

说明

product_key

string

产品标识

device_name

string

设备名称

device_id

string

设备唯一标识

timestamp

int64

时间戳,单位毫秒

biz_code

string

业务标识

data

json 对象

详细业务数据

# 2. 业务类型

biz_code(字符串类型)

说明

device_data

设备状态及事件上报

device_status

设备在线状态变更

device_lifecycle

设备生命周期变更

device_topo

设备拓扑结构变更

ota_progress

ota 升级进度

ota_version

ota 模块版本号上报

thing_model

物模型变更通知

# 3. 数据格式

# 3.1 设备数据上报

message_type(设备数据类型)

说明

thing_property

设备属性数据

thing_event

设备事件数据

thing_service

设备服务调用返回数据

thing_hex

设备 hex 数据

user_topic

用户自定义 topic 数据

  1. 设备属性变更
  • 数据格式:
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx",        //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "device_data",  //业务标识
    "data": {
        "message_type": "thing_property",
        "properties": {
            "prop1": "val1",
            "prop2": "val2"
        }
    }
}
  1. 设备事件通知
  • 数据格式
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx",        //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "device_data",  //业务标识
    "data": {
        "message_type": "thing_event",
        "events": {
            "event1": {
                "value": {
                    "param1": "xxx",
                    "param2": 1
                },
                "timestamp": 1635146586
            },
            "event2": {
                "value": {
                    "param1": "xxx",
                    "param2": 1
                },
                "timestamp": 1635146586
            }
        }
    }
}
  1. 设备服务调用返回
  • 数据格式:
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx",        //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "device_data",  //业务标识
    "data": {
        "message_type": "thing_service",
        "services": {
            "service1": {       //设备服务identifier
                "value": {
                    "param1": 1,    //输出参数1
                    "param2": 2     //输出参数2
                },
                "message_id": "10"  //消息id,对应服务调用时的消息id
            }
        }
    }
}
  1. 自定义 topic 数据
  • 数据格式:
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx",        //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "device_data",  //业务标识
    "data": {
        "message_type": "user_topic",
        "user_topic": "xxxx",    //自定义topic
        "user_payload": "xxxx"   //base64编码后的payload
    }
}

# 3.2 设备在线状态

  • 数据格式:
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx", //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "device_status", //业务标识
    "data": {
        "status": "online" //online-在线,offline-离线
    }
}
  • 参数说明:

参数

类型

说明

status

string

online-在线,offline-离线

# 3.3 设备生命周期变更

  • 数据格式:
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx", //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "device_lifecycle", //业务标识
    "data": {
        "action": "bind",
        "random": "xxxx" //用于业务服务器配网设备身份识别
    }
}
  • 参数说明:

参数

类型

说明

action

string

bind-设备绑定, unbind-设备解绑, delete-设备删除, enable-设备启用, disable-设备禁用,

active-设备激活,

create-设备新增,

dynamic.create-设备动态生成

dynamic.register-设备动态注册

random

string

设备配网唯一标识(仅设备绑定时有效)

# 3.4 设备拓扑关系变更

  • 数据格式:
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx", //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "device_topo", //业务标识
    "data": {
        "action": "add",
        "success": [
            {
                "device_name": "xxx",
                "product_key": "xxx",
                "device_id": "xxx",
                "session_id": "xxx" //配网请求唯一标识
            }
        ],
        "failure": [
            {
                "device_name": "xxx",
                "product_key": "xxx",
                "session_id": "xxx"
            }
        ]
    }
}
  • 参数说明:

参数

类型

说明

aciton

string

add-新增拓扑关系, delete-删除拓扑关系

success

array

操作成功的子设备身份列表

failure

array

操作失败的子设备身份列表

# 3.5 ota 升级进度通知

  • 数据格式
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx", //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "ota_progress", //业务标识
    "data": {
        "step": 10,
        "module": "default",
        "task_id": "xxx"
    }
}
  • 参数说明:

参数

类型

说明

step

int32

0~100:升级进度, -1:升级失败,

module

string

固件模块标识

task_id

string

对应升级任务标识

# 3.6 ota 模块版本号通知

  • 数据格式
{
    "product_key": "xxx",
    "device_name": "xxx",
    "device_id": "xxxx", //设备唯一id
    "timestamp": 1635146586120, //时间戳,单位:毫秒
    "biz_code": "ota_version", //业务标识
    "data": {
        "version": "1.5.1",
        "module": "default"
    }
}
  • 参数说明:

参数

类型

说明

version

string

设备当前模块版本号,格式:"x.y.z"

module

string

固件模块标识

# 3.7 物模型变更通知

  • 数据格式
{
    "product_key":"xxxxx",
    "biz_code":"thing_model",
    "timestamp":1648802119362,
    "data":{
        "action":"POST",         // 操作类型 POST/PUT/DELETE
        "element_id":"",			   // 物模型元素id
        "element_type":"event",  // 物模型元素类型:property/event/service
        "element_data":{				 // 物模型元素数据
            "id":"xxxxx",
            "name":"xxxxx",
            "required":false,
            "standard":false,
            "eventType":"alert",
            "desc":"",
            "outputData":{
                "event_param":{
                    "id":"xxxxx",
                    "name":"xxxxx",
                    "dataType":{
                        "min":"1",
                        "max":"99",
                        "step":"1",
                        "type":"int"
                    }
                }
            }
        }
    }
}
更新时间: 2023/3/22 下午5:14:10