我按照ZCL报告实现了能够接收传感器发送的数据的功能。
在SDk中,它的定义如下:
void ZbZclReportFunc{
struct ZbZclClusterT * clusterPtr,
zbApsdeDataInt * dataIndPtr,
uint16_t attributeId,
const uint8_t * data
}
通过实现如上所示的回调函数,我能够接收除数据之外的所有信息。
在 ZCL 规范中,温度测量集群定义了其“MeasuredValue”有符号 16 位整数。
我使用以下格式打印数据:
printf("Degree: 0x%04x", *data);
正如我所料,显示的数据是“0x002b”作为示例。
通过将其转换为有符号 16 位整数,没有任何帮助。
printf("Degree: 0x%04x", (int16_t)*data);
有什么想法吗?
谢谢
最佳答案
Zigbee 数据包数据为小端字节序。此外,MeasuredValue 的单位是“百分之几摄氏度”。因此,如果您测量的温度值为 26 摄氏度,您的数据缓冲区将如下所示:28 0A
。要转换为摄氏度,您可以使用:
double temperature = (double)((int16_t)(data[1] << 8) | (int16_t)data[0]) / 100.0;
关于zigbee 模块回调函数与 ZCL 规范不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31064194/