Updated on 2022-02-24 GMT+08:00

Codec Development

Overview

When a device reports data, if Data Type is Binary, a codec needs to be developed for the product. If Data Type is JSON, codec development is not required.

For example, in the NB-IoT scenario where devices communicate with the IoT platform using CoAP, the payload of the CoAP message is the data at the application layer and the data type is defined by the device. As NB-IoT devices have demanding requirements on power saving, data at the application layer is in binary format instead of JSON format. However, the IoT platform communicates with NAs by sending data in JSON format. Therefore, codec development is needed for the IoT platform to convert data in binary and JSON formats.

Developing a Codec

When you are Customizing a Product, if the system template is used, you can directly use or modify the codecs contained in some of the templates. If you choose to customize a product, you need to develop a complete codec. The development process is as follows:

  1. In the product development space, click Codec Development.

  2. In the Online Codec Editor area, click Add Message.

  3. In the Add Message dialog box displayed, specify Message Name, set Message Type to Data Reporting, and click OK.

    • If the IoT platform is required to return an ACK message after the device reports data, Add Response Field must be selected. The data carried in the ACK message can be configured in Response. The default value is AAAA0000.
    • Message Name can contain only letters, digits, underscores (_), and dollar signs ($) and cannot start with a digit.

  4. Click + next to Data Reporting Fields.

  5. In the Add Field dialog box displayed, select Tagged as address field and other parameters will be set automatically. Then, click OK.

    When messages of the same type are created, such as two data reporting messages, this option must be selected and this field in every such message must be in the same place on the field list. Command response can be regarded as a type of data reporting message. Therefore, if a command response exists, an address field needs to be added to the data reporting message.

  6. Click + next to Data Reporting Fields.

  7. In the Add Field dialog box displayed, set the parameters and click OK.

    • Name can contain only letters, digits, underscores (_), and dollar signs ($) and cannot start with a digit.
    • Data Type is configured based on the data reported by the device and must match the type of the corresponding field defined by the profile.

  8. In the Online Codec Editor area, click Add Message.

  9. In the Add Message dialog box displayed, specify Message Name, set Message Type to Command Delivery, and click OK.

    • If the device is required to return the command execution result, select Add Response Field. After the check box is selected:
      • The address field must be defined in both the data reporting message and the command response, and this field in the two messages must be in the same place on the field list, so that the codec can distinguish the data reporting message from the command response.
      • The response ID field must be defined in the command delivery message and the command response, and this field in the two messages must be in the same place on the field list, so that the codec can associate the command delivery message with the corresponding command response.
    • Message Name can contain only letters, digits, underscores (_), and dollar signs ($) and cannot start with a digit.

  10. Click + next to Command Delivery Fields.

  11. In the Add Field dialog box displayed, select Tagged as address field and other parameters will be set automatically. Then, click OK.

    When messages of the same type are created, such as two command delivery messages, this option must be selected and this field in every such message must be in the same place on the field list. Data reporting response can be regarded as a type of command delivery message. Therefore, if a data reporting response exists, an address field needs to be added to the command delivery message.

  12. Click + next to Command Delivery Fields.

  13. In the Add Field dialog box displayed, select Tagged as response ID field and other parameters will be set automatically. Then, click OK.

  14. Click + next to Command Delivery Fields.

  15. In the Add Field dialog box displayed, set the parameters and click OK.

    • Name can contain only letters, digits, underscores (_), and dollar signs ($) and cannot start with a digit.
    • Data Type is configured based on the data reported by the device and must match the type of the corresponding field defined by the profile.

  16. Click + next to Response Fields.

  17. In the Add Field dialog box displayed, select Tagged as address field and other parameters will be set automatically. Then, click OK.

  18. Click + next to Response Fields.

  19. In the Add Field dialog box displayed, select Tagged as response ID field and other parameters will be set automatically. Then, click OK.

  20. Click + next to Response Fields.

  21. In the Add Field dialog box displayed, select Tagged as command execution state field, set the parameters, and click OK.

    • The value of Name is automatically populated.
    • Data Type is configured according to the actual command response and must match the type of the corresponding field defined by the profile.

  22. Click + next to Response Fields.

  23. In the Add Field dialog box displayed, set the parameters and click OK.

    • Name can contain only letters, digits, underscores (_), and dollar signs ($) and cannot start with a digit.
    • Data Type is configured based on the data reported by the device and must match the type defined by the profile.

  24. Map the property fields, command fields, and response fields in Device Model on the right with the corresponding fields in the data reporting message, command delivery message, and command response.

  25. Click Save and then Deploy to deploy the codec on the IoT platform.