cancel
Showing results for 
Search instead for 
Did you mean: 

Zigbee example/help on how to configure and send values ?

Lizerd_
Associate II

Hi all.
I have been working with STM32WB for over a year and now starting up to use zigbee.

Been trying the examples and digging deep into the internet on how to send values from a STM32WB that acts an temperature sensor. Not much info on ST & zigbee.

I can make it show up in the coordinator, but I have not been able to register it as a temperature sensor and send values.

Most of the examples show how to handle OnOff toggle, and its not really clear on how to set it up to send values.
Also to set up multiple values to be able to send multiple sensor types.

If anyone have an example or just like to copy a few lines of how you did it, would help tremendous.

Many big thanks beforehand // Mike

1 ACCEPTED SOLUTION

Accepted Solutions
Ouadi
ST Employee

Hello,

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 :

/* 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 0x000A => 10s)
ZCL_MAX_REPORT = Maximum reporting interval (e.g 0x0014 => 20s)

Consequently, the Attribute report will be received on the report callback mentionned previously at least every 20sec if temperature does not change and 10sec 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

View solution in original post

4 REPLIES 4
Issamos
Lead II

Hello @Lizerd_ 

In this GitHub you can find much exemples in using the STM32WB in a ZigBee project. 2 of them are giving the exemple of the temperature sensor.

Hope this helps you.

Best regards.

II

Lizerd_
Associate II

Hi Issamos.
Super thanks for your response.

Yes have have been checking the github repo, and checking most of them

The example Zigbee_DevTemp_Client_Router is when temperature sent by a request.

              Device 1                                      Device 2
        
             ---------                                      ---------
             |       |         ZbZclReadReq                 |       |
PushB (SW1)=>|Client | -----------------------------------> |Server | <= PushB (SW1) ---> Increase Temp +2C ->ZbZclAttrIntegerWrite
             |       |                                      |       | <= PushB (SW2) ---> Decrease Temp -2C ->ZbZclAttrIntegerWrite
             |       |                                      |       |
             |       |         ZbZclReadRsp                 |       |=>LED Green
   Display <=|       | <----------------------------------- |       |=>LED Red
   Temp info |       |                                      |       |=> Display attributes written
              --------                                      ---------

 And for me it is not really clear on how to make it the other way around, that the end device (Client) should register that it holds temperature and then send update each X seconds.
as a standard sensor node

I have not found any good example for this in the ST repo.

Many thanks // Mike

 

Ouadi
ST Employee

Hello,

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 :

/* 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 0x000A => 10s)
ZCL_MAX_REPORT = Maximum reporting interval (e.g 0x0014 => 20s)

Consequently, the Attribute report will be received on the report callback mentionned previously at least every 20sec if temperature does not change and 10sec 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
ST Employee

Hello @thiagoryker 

It's good to hear that you succeeded to make a zigbee network working, now the answer to your question about sending the measured temperature is exactly what I reported as an answer in the comment above. 

You can follow the steps mentioned to implement the ZCL_TEMP_MEAS_ATTR_MEAS_VAL attribute as a reportable , and you can also refer to the projects in the STM32WB FW Package ..\STM32WB5MM-DK\Applications\Zigbee\Zigbee_TempMeas_Server_Coord and ..\STM32WB5MM-DK\Applications\Zigbee\Zigbee_TempMeas_Client_Router which implements the same mechanisms over the temperature measurement cluster.

Best regards,

Ouadi