这是我目前的上报test
s32 sampleFloorMeasureCB(void *arg){
// printf(" i come sampleFloorMeasureCB\n");
u16 i;
u8 temp,humi;
u8 data[4]={0}; //data[0-1]:temp data[2-3]:humi
zcl_thermostatAttr_t *pThermostatAttr = zcl_thermostatAttrGet();
last_temp = pThermostatAttr->thermostatLocalTemperature;
for(i = 0; i < N; i++)
{
Sht40Handler();
WaitMs(1);
}
if(GetSht40Temp() != -32768)
{
temp = GetSht40Temp();
local_temp = temp * 100;
}
if(GetSht40Hum() != 0)
{
humi = GetSht40Hum();
}
pThermostatAttr->thermostatLocalTemperature = local_temp;
current_temp = pThermostatAttr->thermostatLocalTemperature;
data[0] = lcd_set_temp_data[temp/10];
data[1] = lcd_set_temp_data[temp%10];
data[2] = lcd_set_humi_data[humi/10];
data[3] = lcd_set_humi_data[humi%10];
tx_data_show_open[9] = (data[0] >> 4) & (tx_data_show_open[9] | 0x0f);
tx_data_show_open[10] = (tx_data_show_open[10] | 0xff) & ((data[0] << 4)|(data[1] >> 4));
tx_data_show_open[11] = (tx_data_show_open[11] | 0xf0) & (data[1] << 4);
tx_data_show_open[17] = data[3] | 0x10;
tx_data_show_open[18] = data[2];
if(onoff_status_flag == 0)
{
LcdShowOff();
pThermostatAttr->thermostatSystemMode = 0x00;
}
if(onoff_status_flag == 1 && set_temp >= temp)
{
LcdShowOpenMode(tx_data_show_open);
pThermostatAttr->thermostatSystemMode = 0x04;
}
else if(onoff_status_flag == 1 && set_temp < temp)
{
LcdShowOff();
pThermostatAttr->thermostatSystemMode = 0x00;
}
TheLocalTempChangeReport(last_temp,current_temp);
// printf("temp = %d,humi = %d\n",temp,humi);
return 0;
}
#ifdef ZCL_REPORT
void reportLocalTemperature(s16 current_temp) {
// 设置发送端点和目标设备信息
epInfo_t dstEpInfo;
memset((u8 *)&dstEpInfo, 0, sizeof(epInfo_t));
dstEpInfo.dstAddrMode = APS_SHORT_DSTADDR_WITHEP;
dstEpInfo.dstEp = SAMPLE_SENSOR_ENDPOINT;
dstEpInfo.dstAddr.shortAddr = 0x0000;
dstEpInfo.profileId = HA_PROFILE_ID;
// 本地温度属性信息
u16 attrID = ZCL_ATTRID_HVAC_THERMOSTAT_LOCAL_TEMPERATURE;
u8 dataType = ZCL_DATA_TYPE_INT16;
s16 temperatureValue = current_temp; // 示例温度值 20.00°C
u8 disableDefaultRsp = 1; // 禁用默认响应
// 调用 zcl_report 上报属性
u8 status = zcl_report(1, &dstEpInfo, disableDefaultRsp,
ZCL_FRAME_SERVER_CLIENT_DIR, 0, 0,
ZCL_CLUSTER_HAVC_THERMOSTAT, attrID, dataType,
(u8 *)&temperatureValue);
if (status == ZCL_STA_SUCCESS) {
printf("Temperature reported successfully.\n");
} else {
printf("Failed to report temperature, status: %d\n", status);
}
}
static void TheLocalTempChangeReport(s16 last_temp,s16 current_temp)
{
if(abs(current_temp - last_temp) > STEPBYSTEP && zb_isDeviceJoinedNwk())
{
reportLocalTemperature(current_temp);
}
}
#endif
|