This article describes how to write code to parse Thing Specification Language (TSL) data for products whose Data Type parameter is set to Custom. Sample scripts are provided for parsing upstream and downstream property data.
Step 1: Write a script
Module identifier:Property identifier
. Example: model1:prop_int16
.
Step 2: Test the script online
After you write the script, set the Simulation Type parameter and write simulated data to test the script on the Input Simulation tab.
- Test the script by using simulated property data that a device reports to IoT Platform.
Set the Simulation Type parameter to Upstreamed Device Data, enter the following simulated data, and then click Run.
Note In this example, simulated JavaScript data is used. For more information about the JavaScript sample script, see JavaScript example.For information about Python and PHP sample scripts, see Python example and PHP example.
You can use a tool that converts strings to hexadecimal data to convert the JSON-formatted data into hexadecimal data. For example, if the hexadecimal data after the conversion is
00002233441232013fa00000
, enter the following data:0x00002233441232013fa00000
The data parsing engine converts the pass-through data into JSON-formatted data based on the rules that are defined in the script.
Click the Parsing Results tab and view the parsed data.
{ "method": "thing.event.property.post", "id": "2241348", "params": { "prop_float": 1.25, "prop_int16": 4658, "prop_bool": 1 }, "version": "1.0" }
- Test the script by using simulated result data that IoT Platform returns to a device.
Set the Simulation Type parameter to Received Device Data, enter the following JSON-formatted data, and then click Run.
{ "id": "12345", "version": "1.0", "code": 200, "method": "thing.event.property.post", "data": {} }
The data parsing engine converts the JSON-formatted data into the following data:
0x0200003039c8
- Test the script by using simulated data that IoT Platform sends to a device to request
the device to modify properties.
Set the Simulation Type parameter to Received Device Data, enter the following JSON-formatted data, and then click Run.
{ "method": "thing.service.property.set", "id": "12345", "version": "1.0", "params": { "prop_float": 123.452, "prop_int16": 333, "prop_bool": 1 } }
The data parsing engine converts the JSON-formatted data into the following data:
0x0100003039014d0142f6e76d
- Test the script by using simulated result data that a device returns to IoT Platform
after the device modifies its properties.
Set the Simulation Type parameter to Upstreamed Device Data, enter the following data, and then click Run.
0x0300223344c8
The data parsing engine converts the pass-through data into the following JSON-formatted data:
{ "code": "200", "data": {}, "id": "2241348", "version": "1.0" }
Step 3: Submit the script
After you confirm that the script can properly parse data, click Submit to submit the script to IoT Platform. Then, IoT Platform can call this script to parse upstream and downstream data.

Step 4: Use a physical device for debugging
Before you use the script in your business, use a physical device to communicate with IoT Platform. This verifies that IoT Platform can call the script and parse upstream and downstream data.
- Verify that IoT Platform can call the script to parse upstream property data.
- Use the device to report property data to IoT Platform, such as
0x00002233441232013fa00000
. - In the IoT Platform console, choose in the left-side navigation pane.
- On the Devices page, find the device and click View in the Actions column. On the Device Details page, click the tab and then the Status tab. Check whether the reported property data exists.
- Use the device to report property data to IoT Platform, such as
- Verify that IoT Platform can call the script to parse downstream property data.
- In the IoT Platform console, choose in the left-side navigation pane.
- On the Online Debug page, select the product and device that you want to debug. Select
Default Module. Select the identifier of the property that you want to debug, such as prop_int16.
Set the method to Set. Enter the following data and click Send Command.
{ "method": "thing.service.property.set", "id": "12345", "version": "1.0", "params": { "prop_float": 123.452, "prop_int16": 333, "prop_bool": 1 } }
- Check whether the device receives the command for setting properties.
- On the Device Details page, click the tab and then the Status tab. Check whether the device has reported its current property data.
References
- For information about JavaScript (ECMAScript 5) script templates and examples, see JavaScript example.
- For information about Python 2.7 script templates and examples, see Python example.
- For information about PHP 7.2 script templates and examples, see PHP example.
- For information about the process of data parsing, see What is data parsing?.
- For information about the parsing of data that is sent to custom topics, see Submit a data parsing script.
- For information about the API operations that are used to send messages to devices, see API operations for the use of TSL models and API operations for messaging.