Files
PandaX/iothub/README.md
2024-08-21 17:35:50 +08:00

2.0 KiB
Raw Permalink Blame History

原始数据上报格式

010304026C00883BF0

iothub将原始数据序列化成在规则链中 msg就是以下数据。

{
  "rowdata": "010304026C00883BF0"
}

需要在规则链中通过函数键 进行解析脚本

/*直连设备tempVal是产品物模型中所定义属性的标识符*/
var tempVal = msg.rowdata;
/*物模型温度标识符*/
msg.temperature = (parseInt('0x'+tempVal.substr(10, 4))*0.1).toFixed(2);
/*物模型湿度标识符*/
msg.humidity = (parseInt('0x'+tempVal.substr(6, 4))*0.1).toFixed(2);
return {msg: msg, metadata: metadata, msgType: msgType};

属性上报格式

{
   "attribute1": "value1",
   "attribute2": 0
}

遥测上报格式

{
  "ts": 1689837909000,
  "values": {
    "telemetry1": "value1",
    "telemetry2": 0
  }
}

如果边缘无法获取时间

{
    "telemetry1": "value1",
    "telemetry2": 0
}

网关子设备属性上报格式

devA 为设备标识

{
  "devA": {
    "attribute1": "value1",
    "attribute2": 0
  },
  "devB": {
    "attribute1": "value1",
    "attribute2": 0
  }
}

网关子设备遥测上报格式

devA 为设备标识

{
  "devA": {
      "ts": 1689837909000,
      "values": {
        "telemetry1": "value1",
        "telemetry2": 0
      }
    }
}

或者

{
  "devA": {
    "telemetry1": "value1",
    "telemetry2": 0
    }
}

网关子设备连接或断开上报格式

{
  "devA": "online",
  "devB": "offline"
}

服务端命令下发,设备请求格式,

{
   "method": "restart",
   "params": {
      "firmware_address": "http://xxx.yyy.com",
      "version": "latest",
      "secret": "****",
      "http_method": "GET"
   }
}

服务端属性下发 method: 'setAttributes'

{
  "method": "setAttributes",
  "params": {
     "aa": "2"
   }
}

设备端 请求的格式

{ "method": "getCurrentTime", "params": { "aa": "2" } }

设备端 响应的格式

{ "method": "cmdResp", "params": { "aa": "2" } }