# 数据格式

物联网平台的服务端订阅,是基于Topic中的数据格式来处理和传递数据的。本文介绍数据经过消息转发后的数据格式。

# 设备上下线状态

Topic:/as/mqtt/status/${productKey}/${deviceName}

通过该Topic获取设备的上下线状态。

设备上线的数据格式:


{
  "generateTime": 1755336053953,
  "traceId": "709530e9701a485d9d864920ab40fbab",
  "messageId": "744606626866008064",
  "instanceId": "7159249318287***",
  "productKey": "5lGrWBu***",
  "deviceName": "0eEtqPFMZbkhxBh***",
  "topic": "/as/mqtt/status/5lGrWBu***/0eEtqPFMZbkhxBh***",
  "content": {
    "instanceId": "7159249318287***",
    "productKey": "5lGrWBu***",
    "deviceName": "0eEtqPFMZbkhxBh***",
    "gmtCreate": 1755336053953,
    "nanosecond": "1755336053953473862",
    "protocol": "mqtt",
    "connectType": "0",
    "clientIp": "39.71.94.226",
    "status": "online",
    "time": "2025-08-16 17:20:53.953",
    "lastTime": "2025-08-16 17:20:53.953",
    "utcTime": "2025-08-16T09:20:53.953Z",
    "utcLastTime": "2025-08-16T09:20:53.953Z"
  }
}

设备下线的数据格式:


{
  "generateTime": 1755336058633,
  "traceId": "926985a8ae41477298091a9cf51fd3ba",
  "messageId": "744606646474379264",
  "instanceId": "7159249318287***",
  "productKey": "5lGrWBu***",
  "deviceName": "0eEtqPFMZbkhxBh***",
  "topic": "/as/mqtt/status/5lGrWBu***/0eEtqPFMZbkhxBh***",
  "content": {
    "instanceId": "7159249318287***",
    "productKey": "5lGrWBu***",
    "deviceName": "0eEtqPFMZbkhxBh***",
    "gmtCreate": 1755336058633,
    "nanosecond": "1755336058633326373",
    "protocol": "mqtt",
    "connectType": "0",
    "clientIp": "39.71.94.226",
    "status": "offline",
    "time": "2025-08-16 17:20:58.633",
    "lastTime": "2025-08-16 17:20:58.633",
    "utcTime": "2025-08-16T09:20:58.633Z",
    "utcLastTime": "2025-08-16T09:20:58.633Z",
    "offlineReason": "normal",
    "offlineReasonCode": "200"
  }
}

参数说明:

参数 类型 说明
generateTime Long 数据流转消息产生时间。
traceId String traceId。
messageId String messageId。
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
topic String topic。
content Object
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
gmtCreate Long 设备上下线时间。
nanosecond String 设备上下线时间(纳秒级)。
protocol String 协议:mqtt。
connectType String 0。
clientIp String 设备公网出口IP。
status String 设备状态。online:上线。offline:离线。
time String 设备上、下线的时间。收到消息的顺序不是实际设备上下线时间排序。设备上下线顺序需按照time具体值排序。例如,您依次收到3条消息:上线:2018-08-31 10:02:28.195。下线:2018-08-31 10:01:28.195。下线:2018-08-31 10:03:28.195。这3条消息展示了,设备先下线,再上线,最后下线的过程。
lastTime String 该参数为历史存量字段,已无实际意义。
utcLastTime String 该参数为历史存量字段,已无实际意义。
utcTime String 设备上、下线的UTC时间。
offlineReason String 设备离线原因:
normal:设备端主动断开
kicked:服务端踢出
keepalive_timeout:keepalive 超时
tcp_closed:设备端关闭了网络连接
discarded: 另一个设备端使用相同的 ClientID 连接并设置 clean_start = true
takenover: 另一个设备端使用相同的 ClientID 连接并设置 clean_start = false
internal_error:畸形报文或其他未知错误
offlineReasonCode String 设备下线时,返回的错误码。

# 透传上报

Topic:/${productKey}/${deviceName}/thing/model/up_raw

通过该Topic获取设备的透传上报数据。

数据格式:


{
  "generateTime": 1755481198893,
  "traceId": "a7d7781ec8c84c80bc79cf72d2d029bc",
  "messageId": "745215408851652608",
  "instanceId": "7159249318287***",
  "productKey": "5lGrWBu***",
  "deviceName": "0eEtqPFMZbkhxBh***",
  "topic": "/5lGrWBu***/0eEtqPFMZbkhxBh***/thing/model/up_raw",
  "content": "ewogICAgImNvZGUiOiAyMDAsCiAgICAiZGF0YSI6IHt9LAogICAgImlkIjogIjE4NDUwMTg0MDEiLAogICAgIm1lc3NhZ2UiOiAic3VjY2VzcyIsCiAgICAidmVyc2lvbiI6ICIxLjAiCn0="
}

参数说明:

参数 类型 说明
generateTime Long 数据流转消息产生时间。
traceId String traceId。
messageId String messageId。
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
topic String topic。
content String 经过base64编码的透传数据。

# 设备属性上报

Topic:/${productKey}/${deviceName}/thing/event/property/post

通过该Topic获取设备上报的属性信息。

数据格式:


{
  "generateTime": 1755481690046,
  "traceId": "3dd4547aadb94ea4ae5add6ddb7d9a83",
  "messageId": "745217472042373120",
  "instanceId": "7159249318287***",
  "productKey": "5lGrWBu***",
  "deviceName": "0eEtqPFMZbkhxBh***",
  "topic": "/5lGrWBu***/0eEtqPFMZbkhxBh***/thing/event/property/post",
  "content": {
    "instanceId": "7159249318287***",
    "productKey": "5lGrWBu***",
    "deviceName": "0eEtqPFMZbkhxBh***",
    "gmtCreate": 1755481690046,
    "items": {
      "Power": {
        "time": 1755481690046,
        "value": "2"
      }
    }
  }
}

参数说明:

参数 类型 说明
generateTime Long 数据流转消息产生时间。
traceId String traceId。
messageId String messageId。
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
topic String topic。
content Object
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
gmtCreate Long 数据流转消息产生时间。
items Object 设备数据。
Power Object 属性标识符。产品所具有的属性名称请参见产品的TSL描述。数据格式为: {"items": {"Power": {"time": 1755481690046,"value": "2"}}}

# 设备事件上报

Topic:/${productKey}/${deviceName}/thing/event/${tsl.event.identifier}/post

通过该Topic获取设备上报的事件信息。

数据格式:


{
  "generateTime": 1755482797067,
  "traceId": "04f0d3342d6b42e0ab9aca01817e7e3a",
  "messageId": "745222112075059200",
  "instanceId": "7159249318287***",
  "productKey": "5lGrWBu***",
  "deviceName": "0eEtqPFMZbkhxBh***",
  "topic": "/5lGrWBu***/0eEtqPFMZbkhxBh***/thing/event/WFA/post",
  "content": {
    "instanceId": "7159249318287***",
    "productKey": "5lGrWBu***",
    "deviceName": "0eEtqPFMZbkhxBh***",
    "gmtCreate": 1755481690046,
    "value": {
      "WFA": 1,
      "wfb": 2
    }
  }
}

参数说明:

参数 类型 说明
generateTime Long 数据流转消息产生时间。
traceId String traceId。
messageId String messageId。
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
topic String topic。
content Object
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
gmtCreate Long 数据流转消息产生时间。
value Object 事件的输出参数信息。如以上示例中的两个参数WFA和wfb的信息。数据格式为:{"WFA":1,"wfb":2}

# 自定义 Topic

Topic:/${productKey}/${deviceName}/user/${TopicShortName}

通过该Topic获取设备的自定义Topic上报数据。

数据格式:


{
  "generateTime": 1755483537999,
  "traceId": "5d10eeb4a1f0442fbb435510d9dd832a",
  "messageId": "745225219769110528",
  "instanceId": "7159249318287***",
  "productKey": "5lGrWBu***",
  "deviceName": "0eEtqPFMZbkhxBh***",
  "topic": "/5lGrWBu***/0eEtqPFMZbkhxBh***/user/fabu",
  "content": "ewogICAgImNvZGUiOiAyMDAsCiAgICAiZGF0YSI6IHt9LAogICAgImlkIjogIjE4NDUwMTg0MDEiLAogICAgIm1lc3NhZ2UiOiAic3VjY2VzcyIsCiAgICAidmVyc2lvbiI6ICIxLjAiCn0="
}

参数说明:

参数 类型 说明
generateTime Long 数据流转消息产生时间。
traceId String traceId。
messageId String messageId。
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
topic String topic。
content String 经过base64编码的自定义数据。

# OTA模块版本号变更通知

Topic:/${productKey}/${deviceName}/ota/version/post

通过该Topic获得设备上报的OTA模块版本号。当设备上报OTA模块版本号,且版本号有变更时进行转发。

数据格式:


{
  "generateTime": 1755484175764,
  "traceId": "1e98a88362d8411abfec9a2c8e49ebc5",
  "messageId": "745227894816509952",
  "instanceId": "7159249318287***",
  "productKey": "5lGrWBu***",
  "deviceName": "0eEtqPFMZbkhxBh***",
  "topic": "/5lGrWBu***/0eEtqPFMZbkhxBh***/ota/version/post",
  "content": {
    "productKey": "5lGrWBu***",
    "deviceName": "0eEtqPFMZbkhxBh***",
    "messageCreateTime": 1755484175764,
    "moduleName": "default",
    "moduleVersion": "1.0.12"
  }
}

参数说明:

参数 类型 说明
generateTime Long 数据流转消息产生时间。
traceId String traceId。
messageId String messageId。
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
topic String topic。
content Object
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
messageCreateTime Long 消息产生时间戳,单位毫秒。
moduleName String 模块名称。
moduleVersion String 模块版本号。

# OTA升级进度通知

Topic:/${productKey}/${deviceName}/ota/progress/post

通过该Topic获得OTA升级中进度消息。

数据格式:


{
  "generateTime": 1755484651374,
  "traceId": "8527e7edcd854013af1039e14d1d480b",
  "messageId": "745229889635880960",
  "instanceId": "7159249318287***",
  "productKey": "5lGrWBu***",
  "deviceName": "0eEtqPFMZbkhxBh***",
  "topic": "/5lGrWBu***/0eEtqPFMZbkhxBh***/ota/progress/post",
  "content": {
    "productKey": "5lGrWBu***",
    "deviceName": "0eEtqPFMZbkhxBh***",
    "messageCreateTime": 1755484651374,
    "desc": "OTA升级",
    "destVersion": "aaa",
    "moduleName": "default",
    "srcVersion": "1.0.12",
    "status": "IN_PROGRESS",
    "step": 22,
    "taskId": "7452274887659***",
    "taskSonId": "7452274887785***"
  }
}

参数说明:

参数 类型 说明
generateTime Long 数据流转消息产生时间。
traceId String traceId。
messageId String messageId。
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
topic String topic。
content Object
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
messageCreateTime Long 消息产生时间戳,单位毫秒。
desc String 升级状态描述信息。
destVersion String 升级目标版本。
moduleName String OTA模块名称。
srcVersion String 升级前的版本。
status String 升级状态。IN_PROGRESS:升级中。SUCCEEDED:升级成功。UPGRADE_FAILED:升级失败。DOWNLOAD_FAILED:下载失败。VERIFICATION_FAILED:校验失败。BURN_OPERATION_FAILED:烧写失败。CANCELED:取消升级。
step Integer 设备上报的升级进度。
taskId String 升级批次ID,升级批次的唯一标识符。
taskSonId String 设备升级记录的唯一标识符。

# 属性设置、服务调用响应

Topic:/${productKey}/${deviceName}/thing/downlink/reply/message

通过该Topic可以获取,通过异步方式下发属性设置和服务调用指令给设备,设备进行处理后返回的结果信息。

数据格式:


{
  "generateTime": 1755485268090,
  "traceId": "10467d2253124940906a4dc0020c1814",
  "messageId": "745232476728725504",
  "instanceId": "7159249318287***",
  "productKey": "5lGrWBu***",
  "deviceName": "0eEtqPFMZbkhxBh***",
  "topic": "/5lGrWBu***/0eEtqPFMZbkhxBh***/thing/downlink/reply/message",
  "content": {
    "productKey": "5lGrWBu***",
    "deviceName": "0eEtqPFMZbkhxBh***",
    "code": "200",
    "data": {},
    "gmtCreate": 1755485268090,
    "message": "success",
    "requestId": "3597721300",
    "source": "DEVICE",
    "topic": "/sys/5lGrWBu***/0eEtqPFMZbkhxBh***/thing/service/property/set_reply"
  }
}

参数说明:

参数 类型 说明
generateTime Long 数据流转消息产生时间。
traceId String traceId。
messageId String messageId。
instanceId String 实例ID。
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
topic String topic。
content Object
productKey String 设备所属产品的唯一标识。
deviceName String 设备名称。
code String 设备回复的结果状态码。
data Object 设备返回的结果。
gmtCreate Long 时间戳。
message String 设备回复的结果状态码信息。
requestId String 设备上报消息的原始数据中的Id。
source String 来源。
topic String 设备响应的Topic信息。