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

Codec for Data Reporting and Command Delivery

Scenarios

A smoke detector provides the following functions:

  • Reporting smoke alarms (fire severity) and temperature
  • 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.

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.

    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 command delivery message.

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

  4. Map the property fields and command fields in Device Model on the right with the fields in the data reporting message and command delivery message.

  5. 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 (02013A) is reported. In this code stream, 02 indicates the fire severity and its length is one byte. 013A indicates the temperature and its length is two bytes.

    View the data reporting result ({level=2, temperature=314}) in Application Simulator. 2 is the decimal number converted from the hexadecimal number 02 and 314 from the hexadecimal number 013A.

  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.