cancel
Showing results for 
Search instead for 
Did you mean: 

How to get STM32WB to report automatic to Zigbee2MQTT?

KFisc.2
Associate

Hi

I am creating my own Zigbee sensor, where i have add support for it in Zigbee2MQTT, however I am not sure on how the set the STM32WB up to automatic report its measured temperature values up?

I can select the endpoint, cluster, attributes i want to read from the STM32WB from Zigbee2MQTT and get the correct value, but im not sure what to use for setting it up, when the STM32WB join my network.

I make this call to save the value for it to read, but how to i report it. I want it to be updated every 5 second?

status = ZbZclAttrIntegerWrite(zigbee_app_info.temperature_meas_server_1, ZCL_TEMP_MEAS_ATTR_MEAS_VAL, i16CurrentTemperature);

The STM32WB is setup as an enddevice, with temperature as a server.

Best regards

K-Fischer

4 REPLIES 4
nza
Associate

@KFisc.2​, I am facing the same problem, were you able to solve this already? Maybe @SFern.2​  can help us, I think he has a similar setup (SED with temperature server and Zigbee2MQTT or similar) according to his question (how to disable any kind of polling in sed devices).

JB1234
Associate II

Did you manage to solve this? I'm also stuck unable to report cluster data to z2m.

 

 

Lizerd_
Associate II

Hi All. @nza @KFisc.2 @JB1234  did anyone find a solution for this ?

Ouadi
ST Employee

Hi all @KFisc.2 @Lizerd_ @JB1234 @nza,

A ZigBee attribute reporting can be used to send the temperature values each X seconds, you may utilize the temperature measurement cluster and configure the ZCL_TEMP_MEAS_ATTR_MEAS_VAL attribute to be reportable.

Here is the configuration you need for this use :

On the Client side (Coordinator):

/* Temp meas client */
zigbee_app_info.temp_meas_client = ZbZclTempMeasClientAlloc(zigbee_app_info.zb,SW1_ENDPOINT);
assert(zigbee_app_info.temp_meas_client != NULL);
zigbee_app_info.temp_meas_client->report = &APP_ZIGBEE_Temp_meas_client_report; <==Callback used to receive ZCL Report
ZbZclClusterEndpointRegister(zigbee_app_info.temp_meas_client);

To configure the attribute reporting, you have to call the function ZbZclAttrReportConfigReq as follow :

static void APP_ZIGBEE_ReportConfig(void)
{
uint16_t rep_change = (uint16_t) ZCL_REPORT_CHANGE;
struct ZbZclAttrReportConfigT report;
report.dst.endpoint = SW1_ENDPOINT;
report.dst.mode = ZB_APSDE_ADDRMODE_SHORT;
report.dst.nwkAddr = 0xFFFF;
report.num_records = 1;
report.record_list[0].direction = ZCL_REPORT_DIRECTION_NORMAL;
report.record_list[0].min = ZCL_MIN_REPORT;
report.record_list[0].max = ZCL_MAX_REPORT;
report.record_list[0].change = 0;
report.record_list[0].attr_id = ZCL_TEMP_MEAS_ATTR_MEAS_VAL;
report.record_list[0].attr_type = ZCL_DATATYPE_SIGNED_16BIT;
ZbZclAttrReportConfigReq(zigbee_app_info.temp_meas_client,&report,&APP_ZIGBEE_Report_cb,(void*)&rep_change);
}/*APP_ZIGBEE_ReportConfig*/

ZCL_MIN_REPORT = Minimum reporting interval (e.g 0x0005 => 5s)
ZCL_MAX_REPORT = Maximum reporting interval (e.g 0x0014 => 20s)

Consequently, the Attribute report will be received on the report callback mentioned previously at least every 20 sec if temperature does not change and 5 sec if it changes.

On the server side ( ED temperature sensor ) :
The configuration is as follow:
/* Temp meas server */
zigbee_app_info.temp_meas_server = ZbZclTempMeasServerAlloc(zigbee_app_info.zb,SW1_ENDPOINT,MIN_MEASURED_TEMP,MAX_MEASURED_TEMP,TOLERANCE_TEMP);
The Binding entry is added automatically when the ZbZclAttrReportConfigReq is called from the client.

Now the configuration of the reporting is done, the temperature value is sent after each time intervall or when the value is changed.
To update the temperature attribute value with the measured temperature, the function ZbZclAttrIntegerWrite need to be used as follow:
void APP_ZIGBEE_WriteTempAttribute(float temp_val)
{
enum ZclStatusCodeT status;
float temp = temp_val*100;
int16_t temp_val_attr;
/* Write attribute */
temp_val_attr = (int16_t) temp ;
status = ZbZclAttrIntegerWrite(zigbee_app_info.temp_meas_server, ZCL_TEMP_MEAS_ATTR_MEAS_VAL, (int16_t)temp_val_attr);
}/*APP

You can also refer to the project example in the STM32WB FW Package ..\Projects\STM32WB5MM-DK\Applications\Zigbee\Zigbee_TempMeas_Server_Coord and ..\Projects\STM32WB5MM-DK\Applications\Zigbee\Zigbee_TempMeas_Client_Router which implements the same mechanisms over the temperature measurement cluster.

Best regards

Ouadi