czigbee

zigbee module callback function incompatible to ZCL spec


I have followed the ZCL report to implement the function which is able to receive the data sent from the sensor.

In the SDk, it is defined as the following:

void ZbZclReportFunc{
  struct ZbZclClusterT * clusterPtr,
  zbApsdeDataInt * dataIndPtr,
  uint16_t attributeId,
  const uint8_t * data
}

By implementing the callback function as shown above, I am able to receive all information except data.

In ZCL spec, the Temperature Measurement Cluster defines its "MeasuredValue" Signed 16-bit Integer.

I print out the data using the following format:

printf("Degree: 0x%04x", *data);

As I expect, the data shown is "0x002b" as an example.

By casting it to Signed 16-bit integer, it does not help.

printf("Degree: 0x%04x", (int16_t)*data);

Any idea?


Solution

  • Zigbee packet data is little Endian. Also, the units for MeasuredValue are "hundredths of degrees Celsius". So if your measured temperature value was 26 degrees celsius, your data buffer would look like: 28 0A. To convert to celsius you would use:

    double temperature = (double)((int16_t)(data[1] << 8) | (int16_t)data[0]) / 100.0;