The standard data format defined for device messages in IoT Platform is Alink JSON. Devices that have limited resources and low specifications or devices that require high network throughput cannot use JSON data to communicate with IoT Platform. To resolve the issue, you can pass through raw data from devices to IoT Platform. IoT Platform provides the message parsing feature that converts data between device-specific formats and the JSON format based on the scripts that are submitted.
The following types of messages can be parsed:
Upstream messages from custom topics. When devices submit messages to the cloud by using custom topics, the payloads are parsed to JSON data.
Upstream and downstream Thing Specification Language (TSL) messages. IoT Platform converts the custom data of TSL messages submitted by devices to Alink JSON data and converts Alink JSON data sent from IoT Platform to data of a device-specific format.
Parse messages that are sent to custom topics
After a device submits a message by using a custom topic that has the ?_sn=default
parsing tag, IoT Platform runs the message parsing script that you submitted in the IoT Platform console to convert the payload of the received message in a custom format to a JSON struct for subsequent processing.
The following figure shows the process of data parsing.
The following figure shows the process of using custom topics to submit data.
For information about how to write a script to parse custom topic data, see the following topics:
Parse TSL messages
When a device of a product whose Data Format parameter is set to Custom communicates with the cloud, IoT Platform runs the data parsing script that you submitted to parse upstream data to standard Alink JSON data and downstream data to custom format data.
After IoT Platform receives a message in a custom format from a device, IoT Platform runs a message parsing script to convert the data of the received message to data in the Alink JSON format, and then processes the converted data. Before IoT Platform sends a message to the device, IoT Platform runs the message parsing script to convert the message in the Alink JSON format to data in the custom format that is used by the device.
The following figure shows the process of data parsing.
The following figure shows the process of submitting pass-through property or event data (upstream data).
The following figure shows the process of calling device services or configuring device properties (downstream data).
For more information about the examples on how to write message parsing scripts to parse TSL messages, see the following topics: