32
32
33
33
#include " Zigbee.h"
34
34
35
- #define USE_GLOBAL_ON_RESPONSE_CALLBACK 1 // Set to 0 to use local callback specified directly for the endpoint.
35
+ #define USE_GLOBAL_ON_RESPONSE_CALLBACK 1 // Set to 0 to use local callback specified directly for the endpoint.
36
36
37
37
/* Zigbee temperature + humidity sensor configuration */
38
38
#define TEMP_SENSOR_ENDPOINT_NUMBER 10
@@ -45,29 +45,29 @@ uint8_t button = BOOT_PIN;
45
45
46
46
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
47
47
48
- uint8_t dataToSend = 2 ; // Temperature and humidity values are reported in same endpoint, so 2 values are reported
49
- bool resend = false ;
48
+ uint8_t dataToSend = 2 ; // Temperature and humidity values are reported in same endpoint, so 2 values are reported
49
+ bool resend = false ;
50
50
51
51
/* *********************** Callbacks *****************************/
52
52
#if USE_GLOBAL_ON_RESPONSE_CALLBACK
53
- void onGlobalResponse (zb_cmd_type_t command, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster){
54
- Serial.printf (" Global response command: %d, status: %s, endpoint: %d, cluster: 0x%04x\r\n " , command, esp_zb_zcl_status_to_name (status), endpoint, cluster);
55
- if ((command == ZB_CMD_REPORT_ATTRIBUTE) && (endpoint == TEMP_SENSOR_ENDPOINT_NUMBER)){
56
- switch (status){
53
+ void onGlobalResponse (zb_cmd_type_t command, esp_zb_zcl_status_t status, uint8_t endpoint, uint16_t cluster) {
54
+ Serial.printf (" Global response command: %d, status: %s, endpoint: %d, cluster: 0x%04x\r\n " , command, esp_zb_zcl_status_to_name (status), endpoint, cluster);
55
+ if ((command == ZB_CMD_REPORT_ATTRIBUTE) && (endpoint == TEMP_SENSOR_ENDPOINT_NUMBER)) {
56
+ switch (status) {
57
57
case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break ;
58
- case ESP_ZB_ZCL_STATUS_FAIL: resend = true ; break ;
59
- default : break ;// add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc.
58
+ case ESP_ZB_ZCL_STATUS_FAIL: resend = true ; break ;
59
+ default : break ; // add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc.
60
60
}
61
61
}
62
62
}
63
63
#else
64
- void onResponse (zb_cmd_type_t command, esp_zb_zcl_status_t status){
64
+ void onResponse (zb_cmd_type_t command, esp_zb_zcl_status_t status) {
65
65
Serial.printf (" Response command: %d, status: %s\r\n " , command, esp_zb_zcl_status_to_name (status));
66
- if (command == ZB_CMD_REPORT_ATTRIBUTE){
67
- switch (status){
66
+ if (command == ZB_CMD_REPORT_ATTRIBUTE) {
67
+ switch (status) {
68
68
case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break ;
69
- case ESP_ZB_ZCL_STATUS_FAIL: resend = true ; break ;
70
- default : break ;// add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc.
69
+ case ESP_ZB_ZCL_STATUS_FAIL: resend = true ; break ;
70
+ default : break ; // add more statuses like ESP_ZB_ZCL_STATUS_INVALID_VALUE, ESP_ZB_ZCL_STATUS_TIMEOUT etc.
71
71
}
72
72
}
73
73
}
@@ -85,29 +85,28 @@ static void meausureAndSleep(void *arg) {
85
85
zbTempSensor.setTemperature (temperature);
86
86
zbTempSensor.setHumidity (humidity);
87
87
88
-
89
88
// Report temperature and humidity values
90
- zbTempSensor.report (); // reports temperature and humidity values (if humidity sensor is not added, only temperature is reported)
89
+ zbTempSensor.report (); // reports temperature and humidity values (if humidity sensor is not added, only temperature is reported)
91
90
Serial.printf (" Reported temperature: %.2f°C, Humidity: %.2f%%\r\n " , temperature, humidity);
92
91
93
92
unsigned long startTime = millis ();
94
93
const unsigned long timeout = REPORT_TIMEOUT;
95
94
96
95
Serial.printf (" Waiting for data report to be confirmed \r\n " );
97
96
// Wait until data was succesfully sent
98
- while (dataToSend != 0 ){
99
- if (resend){
100
- Serial.println (" Resending data on failure!" );
101
- resend = false ;
102
- dataToSend = 2 ;
103
- zbTempSensor.report (); // report again
97
+ while (dataToSend != 0 ) {
98
+ if (resend) {
99
+ Serial.println (" Resending data on failure!" );
100
+ resend = false ;
101
+ dataToSend = 2 ;
102
+ zbTempSensor.report (); // report again
104
103
}
105
104
if (millis () - startTime >= timeout) {
106
105
Serial.println (" Report timeout!" );
107
106
break ;
108
107
}
109
108
Serial.printf (" ." );
110
- delay (50 ); // 50ms delay to avoid busy-waiting
109
+ delay (50 ); // 50ms delay to avoid busy-waiting
111
110
}
112
111
113
112
// Put device to deep sleep after data was sent successfully or timeout
@@ -176,8 +175,8 @@ void setup() {
176
175
Serial.println ();
177
176
Serial.println (" Successfully connected to Zigbee network" );
178
177
179
- // Start Temperature sensor reading task
180
- xTaskCreate (meausureAndSleep, " temp_sensor_update" , 2048 , NULL , 10 , NULL );
178
+ // Start Temperature sensor reading task
179
+ xTaskCreate (meausureAndSleep, " temp_sensor_update" , 2048 , NULL , 10 , NULL );
181
180
}
182
181
183
182
void loop () {
0 commit comments