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

Codec for Multiple Data Reporting Messages

Scenarios

A smoke detector provides the following functions:

  • Smoke alarms (fire severity) and temperature reporting
  • Remote command, which can enable the alarm function remotely

    For example, the smoke detector can report the temperature on the fire scene and remotely trigger the smoke alarm for evacuation.

  • Reporting smoke alarms (fire severity) and temperature simultaneously, or reporting the temperature separately.

Defining the Profile File

Define the profile file in the development space of the smoke sensor.
  • level: indicates the fire severity.
  • temperature: indicates the temperature at the fire scene.
  • SET_ALARM: indicates whether to enable or disable the alarm function. The value 0 indicates that the alarm is disabled, and the value 1 indicates that the alarm is enabled.

Developing a Codec

  1. In the development space of the smoke sensor, click Codec Development.

  2. Configure a data reporting message to report the fire severity and temperature.

    Add the messageId field to indicate the message type.

    • In this scenario, there are two types of data reporting messages. Therefore, the messageId field must be defined to identify the message type.
    • Data Type is configured based on the number of data reporting message types. In this scenario, only two types of data reporting messages are available. Therefore, the value int8u will suffice.
    • Default Value can be changed but must be in hexadecimal format. In addition, the corresponding field in data reporting messages must be the same as the default value. In this scenario, the value 0x0 is used to identify the message that reports the fire severity and temperature.

    Add a level field to indicate the fire severity.
    • 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 in the profile file.
    • The values of Length and Offset are automatically filled based on Data Type.

    Add the temperature field to indicate the temperature at the fire scene. In the profile file, the maximum value of temperature is 1000. Therefore, set the data type of the temperature field to int16u in the codec to meet the value range requirement of temperature.

  3. Configure a data reporting message to report only the temperature.

    Add the messageId field to indicate the message type. In this scenario, the value 0x1 is used to identify the message that reports only the temperature.

    Add the temperature field to indicate the temperature at the fire scene.

  4. Configure a command delivery message.

    Add the value field to indicate the parameter value of the delivered command.

  5. Drag the property fields and command fields in Device Model on the right to set up a mapping with the fields in the data reporting message and command delivery message.

    The level and temperature fields are mapped to the corresponding properties in the profile file. The messageId field is used to identify message types and does not need to be mapped.

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

Testing the Codec

  1. In the development space of the smoke sensor, click Online Testing and add a virtual device to test the codec.

    Select No for Is Physical Device Available and click OK.

  2. Use the device simulator to report data.

    For example, a hexadecimal code stream (000100F1) is reported. In this code stream, 00 indicates the messageId field and specifies that this message reports the fire severity and temperature. 01 indicates the fire severity and its length is one byte. 00F1 indicates the temperature and its length is two bytes.

    View the data reporting result ({level=1, temperature=241}) in Application Simulator. 1 is the decimal number converted from the hexadecimal number 01 and 241 from the hexadecimal number 00F1.

    Take another hexadecimal code stream (0100F1) as an example. 01 indicates the messageId field and specifies that this message reports only the temperature. 00F1 indicates the temperature and its length is two bytes.

    View the data reporting result ({temperature=241}) in Application Simulator. 241 is the decimal number converted from the hexadecimal number 00F1.

  3. Use the application simulator to deliver a command ({ "serviceId": "Smoke", "method": "SET_ALARM", "paras": "{\"value\":1}" }).

    View the command receiving result in Device Simulator, which is 01. 01 is the hexadecimal number converted from the decimal number 1.