Codec Definition
A codec, as a plug-in within the platform, enables the conversion of data between binary and JSON formats or between different JSON formats. It manages the conversion of data from devices to the platform and vice versa.
In the NB-IoT scenario, a codec can decode binary data reported by a device into the JSON format for the application to read, and encode the commands delivered by the application into the binary format for the device to understand and execute. CoAP is used for communications between NB-IoT devices and the IoT platform. The payload of CoAP messages carries data at the application layer, at which the data type is defined by the devices. As NB-IoT devices require low power consumption, data at the application layer is generally in binary format instead of JSON. However, the platform sends data in JSON format to applications. Therefore, codec development is required for the platform to convert data between binary and JSON formats.
Scenarios
1. Required for device access using LwM2M/CoAP
2. Required for device access using generic protocols, such as TCP, JT808, and GB32960
3. Not required for device access using MQTT(S) or HTTP(S)
Data Reporting

In the data reporting process, the codec is used in the following scenarios:
- Decoding binary data reported by a device into JSON data and sending the decoded data to an application
- Encoding JSON data returned by an application into binary data that can be identified by the device and sending the encoded data to a device
Command Delivery

In the command delivery process, the codec is used in the following scenarios:
- Encoding JSON data delivered by an application into binary data and sending the encoded data to a device
- Decoding binary data returned by a device into JSON data and reporting the decoded data to an application
Graphical Development and Script-based Development
The platform provides multiple methods for developing codecs.
- Online development: The codec of a product can be quickly developed in a visualized manner on the IoTDA console.
- Script-based development: JavaScript scripts are used to implement encoding and decoding. After December 1, 2024, JavaScript-based codec development is no longer available on the platform for new users. You are advised to use FunctionGraph to write JavaScript scripts. For details, see Overview.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot