云端-设备通讯协议

topic定义

报文结构

名称 编码 数据类型 描述
消息元数据 meta Metadata
消息数据体 payload Payload
消息路由 route MessageRoute

Metadata

名称 编码 数据类型 描述
消息标识 id STRING
消息类型 type Enum<STRING> m: Measurement普通数据(Default)
log:日志数据
ack:响应数据
c:配置命令
设备标识 deviceid STRING
现场网关标识 gatewayId STRING 通讯网关标识,仅设备通过网关通讯时包含,否则不填为空
消息版本号 version STRING
时间戳 ts LONG Unix时间戳,自 1970 年 1 月 1 日(00:00:00 GMT)以来的秒数
是否需要响应 needack Boolean
关联标识 correlationId STRING 仅当消息类型为ack时需要,取值为请求消息的id

Payload

下行Payload格式

名称 编码 数据类型 描述
属性数据列表 attrs List<PayloadAttribute> 下行:消息类型m
上行:消息类型m
操作列表 actions List<PayloadAction> 下行:消息类型为 m,c
消息响应 resp PayloadResponse 仅当消息类型为ack时需要

PayloadAttribute

名称 编码 数据类型 描述
属性编码 code String
属性值 value Object
属性数据类型 channel Enum<STRING> m: Measurement普通数据(Default)
w:告警数据
g:位置数据

PayloadAction

名称 编码 数据类型 描述
编码 code STRING 操作方法名称,需符合函数名定义规则
参数列表 params Map<String,Object>

PayloadResponse

名称 编码 数据类型 描述
状态 status Integer 状态:
0 成功
其他取值表示失败
响应描述 message String 描述

MessageRoute

名称 编码 数据类型 描述
forwardTopic string 发送消息topic
ackTopic String 响应消息topic

下行消息样例

{
  "meta": {
    "type": "m",
    "deviceid": "839be002-947d-43a2-aceb-40ff95d9484e",
    "version": "1.0.0",
    "ts": 1469564492,
    "needack": false,
    "id": "b69451e2-779b-4275-943b-cf0f6bbeb858"
  },
  "payload": {
    "attrs": [
      {
        "code": "temp",
        "value": 23.8,
        "channel": "m"
      },
      {
        "code": "location",
        "value": "48.1234,72.23",
        "channel": "g"
      },
    ],
    "actions": [
      {
        "code": "poweroff",
        "params": {
          "delay": 20.3,
          "desc": "desc"
        }
      }
    ]
  }
}
{
  "meta": {
    "type": "c",
    "deviceid": "839be002-947d-43a2-aceb-40ff95d9484e",
    "version": "1.0.0",
    "ts": 1469564492,
    "needack": false,
    "id": "b69451e2-779b-4275-943b-cf0f6bbeb858"
  },
  "payload": {
    "actions": [
      {
        "code": "log",
        "params": {
          "isdebug": true,
          "level": "INFO"
        }
      }
    ]
  }
}

上行消息样例

{
  "meta": {
    "type": "m",
    "deviceid": "839be002-947d-43a2-aceb-40ff95d9484e",
    "version": "1.0.0",
    "ts": 1469564492,
    "needack": false,
    "id": "b69451e2-779b-4275-943b-cf0f6bbeb858"
  },
  "payload": {
    "attrs": [
      {
        "code": "temp",
        "value": 23.8,
        "channel": "m"
      },
      {
        "code": "location",
        "value": "48.1234,72.23",
        "channel": "g"
      }
    ]
  }
}
{
    "meta": {
        "type": "w",
        "needack": false,
        "version": "1.0.0",
        "id": "0deb67c1-7770-496d-a05f-28e481920d45",
        "ts": 1562136367014,
        "deviceid": "0dee7ce7-29fa-40b7-b736-82f6591791c7"
    },
    "payload": {
        "alarm": {
            "id": "0deb67c1-7770-496d-a05f-28e481920d45",
            "code": "AreaIntrusionDet",
            "name": "区域入侵检测",
            "description": "有人进入禁止区域",
            "sourceType": "ai",
            "source": "AreaIntrusionDet",
            "device": "0dee7ce7-29fa-40b7-b736-82f6591791c7",
            "level": "warning",
            "origin": 1562136367014,
            "handleResult": "new",
            "contents": [{
                "boxes": [{
                    "confidence": 0.5276447534561157,
                    "h": 0.3722120431753305,
                    "index": 0,
                    "w": 0.0733693929818961,
                    "x": 0.27838343840378976,
                    "y": 0.4787874221801758
                }],
                "level": "warning",
                "origin": 1562136367014,
                "path": "https://private-iot-glodon.oss-cn-beijing.aliyuncs.com/edge/data/image/analyse/0dee7ce7-29fa-40b7-b736-82f6591791c7_1562136366989.jpg",
                "regions": [{
                    "name": "东出口",
                    "polygon": [
                        [0.10185185185185185, 0.2857142857142857],
                        [0.8703703703703703, 0.2857142857142857],
                        [0.8703703703703703, 0.876984126984127],
                        [0.10185185185185185, 0.876984126984127]
                    ]
                }]
            }]
        }
    }
}

响应消息样例

{
  "meta": {
    "type": "ack",
    "deviceid": "862c509c-43a1-4c1a-93db-1a6c0ee517a0",
    "version": "1.0.0",
    "ts": 1469564492,
    "needack": false,
    "id": "abfad39a-6f05-4892-8417-a02d7fa30d60",
    "correlationId": "b69451e2-779b-4275-943b-cf0f6bbeb858"
  },
  "payload": "payload": {
    "resp": {
      "status": 0,
      "message": "success"
    }
  }
}

调试日志API

名称 编码 数据类型 描述
操作标识 action Enum<STRING> log:控制日志信息
是否调试模式 isdebug Boolean true:开启调试模式
false:关闭调试模式
日志等级 level Enum<STRING> INFO,DEBUG,WARN,ERROR