3232
3333#include " Zigbee.h"
3434
35- /* Zigbee OTA configuration */
36-
37- #define OTA_UPGRADE_RUNNING_FILE_VERSION 0x01010100 // Increment this value when the running image is updated
38- #define OTA_UPGRADE_DOWNLOADED_FILE_VERSION 0x01010101 // Increment this value when the downloaded image is updated
39- #define OTA_UPGRADE_HW_VERSION 0x0101 // The hardware version, this can be used to differentiate between different hardware versions
40-
4135#define USE_GLOBAL_ON_RESPONSE_CALLBACK 1 // Set to 0 to use local callback specified directly for the endpoint.
4236
4337/* Zigbee temperature + humidity sensor configuration */
@@ -51,7 +45,6 @@ uint8_t button = BOOT_PIN;
5145
5246ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
5347
54- volatile bool otaInhibitSleep = false ;
5548uint8_t dataToSend = 2 ; // Temperature and humidity values are reported in same endpoint, so 2 values are reported
5649bool resend = false ;
5750
@@ -80,15 +73,6 @@ void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status) {
8073}
8174#endif
8275
83- void otaSleepInhibitCallback (bool otaActive) {
84- otaInhibitSleep = otaActive;
85- if (otaActive) {
86- Serial.println (" OTA started: inhibiting sleep" );
87- } else {
88- Serial.println (" OTA finished: sleep allowed" );
89- }
90- }
91-
9276/* *********************** Temp sensor *****************************/
9377static void meausureAndSleep (void *arg) {
9478 // Measure temperature sensor value
@@ -131,10 +115,8 @@ static void meausureAndSleep(void *arg) {
131115 }
132116
133117 // Put device to deep sleep after data was sent successfully or timeout
134- if (!otaInhibitSleep) {
135- Serial.println (" Going to sleep now" );
136- esp_deep_sleep_start ();
137- }
118+ Serial.println (" Going to sleep now" );
119+ esp_deep_sleep_start ();
138120}
139121
140122/* ******************** Arduino functions **************************/
@@ -150,12 +132,6 @@ void setup() {
150132 // Optional: set Zigbee device name and model
151133 zbTempSensor.setManufacturerAndModel (" Espressif" , " SleepyZigbeeTempSensor" );
152134
153- // Optional: set ota
154- zbTempSensor.addOTAClient (OTA_UPGRADE_RUNNING_FILE_VERSION, OTA_UPGRADE_DOWNLOADED_FILE_VERSION, OTA_UPGRADE_HW_VERSION);
155-
156- // Optional: Register callback for OTA state change (inhibit sleep during OTA)
157- zbTempSensor.onOTAStateChange (otaSleepInhibitCallback);
158-
159135 // Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
160136 zbTempSensor.setMinMaxValue (10 , 50 );
161137
@@ -204,9 +180,6 @@ void setup() {
204180 Serial.println ();
205181 Serial.println (" Successfully connected to Zigbee network" );
206182
207- // Start Zigbee OTA client query, first request is within a minute and the next requests are sent every hour automatically
208- zbTempSensor.requestOTAUpdate ();
209-
210183 // Start Temperature sensor reading task
211184 xTaskCreate (meausureAndSleep, " temp_sensor_update" , 2048 , NULL , 10 , NULL );
212185}
@@ -220,10 +193,6 @@ void loop() {
220193 while (digitalRead (button) == LOW) {
221194 delay (50 );
222195 if ((millis () - startTime) > 10000 ) {
223- if (otaInhibitSleep) {
224- Serial.println (" OTA in progress, cannot reset now" );
225- break ;
226- }
227196 // If key pressed for more than 10secs, factory reset Zigbee and reboot
228197 Serial.println (" Resetting Zigbee to factory and rebooting in 1s." );
229198 delay (1000 );
0 commit comments