Analysis of binary data reported by equipment on IoT platform

Related Tags:1.IoT Platform
2. AliwareMQ for IoT

Abstract: The practice of parsing the binary data reported by the device on the IoT platform

Analysis of binary data reported by equipment on IoT platform

In the IoT scenario, many sensors collect private protocol binary data streams, and the device side does not have the ability to convert them into structured JSON. At this time, the device can report binary data through a custom topic. The IoT IoT platform supports cloud configuration parsing scripts, which can be dynamically converted into structured JSON data.

The complete end-to-end development process is as follows:

1: Define the topic and data format rules of binary reporting

2: The cloud pre configures the JS parsing script for the original data of the specified topic

3: After the script parses the simulation data input and verifies that the script business logic is correct, submit it to the IoT cloud

4: Run the device and specify the topic to report the original data

5: Cloud Log Service View Data Analysis Process

We take the watch as an example. The sensor reports hex data to the IoT Internet of Things platform, analyzes it in the cloud, and finally transfers it to the business system with structured JSON.

1. Technical architecture scheme

Private protocol data conversion link:

Changes before and after message conversion:

2 Cloud development

Product definition and message communication topic selection

Data conversion script

raw data:


Full script content

*Convert the device customized topic data to json format data, and call when the device reports the data to the Internet of Things platform
*Input parameter: topic string, topic of the reported message by the device
*Input parameter: rawData byte [] array cannot be empty
*Output parameter: jsonObj JSON object cannot be empty
function transformPayload(topic, rawData) {
var jsonObj = {}
Raw hex data: 0x035e8192fd0000000d0000001b00000a8c

JSON data after conversion:
"heartbeat": 15,
"id": 1585549855,
"steps": 2700,
"speed": 56

if (topic.endsWith('/user/update')) {
var uint8Array = new Uint8Array(rawData.length);
for (var i = 0; i < rawData.length; i++) {
uint8Array[i] = rawData[i] & 0xff;

var dataView = new DataView(uint8Array.buffer, 0);

var fHead = uint8Array[0]; // command

if (fHead == 0x03) {
jsonObj['id'] = dataView.getInt32(1);
jsonObj['heartbeat'] = dataView.getInt32(5);
jsonObj['speed'] = dataView.getInt32(9);
//Total Steps
jsonObj['steps'] = dataView.getInt32(13);
return jsonObj;

3 Device side development

Code snippet for equipment reporting hex raw data:

const mqtt = require('aliyun-iot-mqtt');

//Device Identity

const options = {

productKey: "a1kaK7XC8oB",

deviceName: "BlXj1yasMJXmpKxymoUC",

deviceSecret: "41798535d799c60c8f67f02efd28b01c",

regionId: "cn-shanghai"


//Establish a connection

const client = mqtt.getAliyunIotMqttClient(options);

//Is the message topic carried_ Sn=default ID

const topic = `/${options.productKey}/${options.deviceName}/user/update?_ sn=default`;

//Raw data

var payloadArray = [ 3, 94, 129, 169, 59, 0, 0, 0, 23, 0, 0, 0, 79, 0, 0, 30, 220 ];

var payload = new Buffer(payloadArray);

//Publish data to topic

client. publish(topic, payload);

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us