Updated on 2024-10-31 GMT+08:00

Codecs

How Can I Develop Codecs?

The IoT platform supports the codec online development. For details, see Online Development.

What Is the Code Rule for Fields of the string and varstring Types?

If Data Type of a field is string(string type) or varstring(variable-length string), the codec performs encoding and decoding using ACSII.

For details on the codec online development, see Codec for Strings and Variable-Length Strings.

Figure 1 Data type example 1

What Is the Code Rule for Fields of the array and variant Types?

If Data Type is array(array type) or variant(variable-length array type), the codec performs encoding and decoding using Base64. For details on the codec online development, see Codec for Arrays and Variable-Length Arrays.

Figure 2 Data type example 2

How Do I Use messageId During Online Codec Development?

When messages of the same type are created, such as two data reporting messages, messageId must be configured to distinguish these messages and this parameter in each message must be in the same place on the list. The messageId field applies to the following scenarios:

  • There are two or more data reporting messages or command delivery messages.
  • A command response can be regarded as a type of data reporting message. Therefore, if a command response exists, messageId must be added to the data reporting message.
  • A data reporting response can be regarded as a type of command delivery message. Therefore, if a data reporting response exists, messageId must be added to the command delivery message.

How Do I Configure a Command Delivery Response During Online Codec Development?

After receiving a command, a device sends an ACK message or a command delivery response. The ACK message indicates that the command has reached the device, and the command delivery response indicates the command execution result. If the device needs to return a command delivery response after receiving the command, the messageId and mid fields must be configured:
  • messageId must be configured 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 list, so that the codec can distinguish between the two.
  • mid must be configured in the command delivery message and the command response, and this field in the two messages must be in the same place on the list, so that the codec can associate the two.

What Do I Do If a Codec That Was Developed Online Fails to Be Deployed?

Description:

You develop a codec on the development page and click Deploy. The deployment fails.

Possible Causes:

  1. If the codec is successfully downloaded but fails to be deployed, there may be network issues.
  2. If the codec fails to be downloaded, the possible causes are as follows:
    • The value of messageId in the messages of the same type (for example, two data reporting messages) is duplicate or their positions in the messages are different.
    • Data Type is not set to int for messageId.
    • The default value of a field is not in hexadecimal format.
    • A field name contains a Java keyword, for example, type or int.

Solutions:

  1. If the codec is successfully downloaded but fails to be deployed, check the network status and try again.
  2. If the codec fails to be downloaded, check whether the codec definition meets the requirements.

What Do I Do If a Script-based Codec or a Codec Developed Offline Fails in Encoding or Decoding?

  • For a script-based codec, choose Products > Codec Development > Edit Script to debug the codec and modify the codec based on the debugging result.
  • For a codec developed offline, debug the codec using the codec test tool and modify the codec based on the test result.

What Do I Do If a Codec That Was Developed Offline Fails to Be Deployed?

  1. Use the IoT codec test tool to check the codec.
  2. Rectify the fault based on the error code returned by the tool. For details on how to handle different errors, see User Guide for IoT Codec Test Tool in the tool package.

What Do I Do If a Codec That Was Developed Offline Fails to Be Uploaded?

Codecs that are developed offline must be checked before being uploaded to the IoT platform. Use the IoT codec test tool to check the codec package and rectify the fault based on the error message.