Skip to content

Commit 69e7d9c

Browse files
committed
feat(zigbee examples): revert sleepy temp hum sensor instead add example to ota client
1 parent a816430 commit 69e7d9c

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

libraries/Zigbee/examples/Zigbee_OTA_Client/Zigbee_OTA_Client.ino

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ uint8_t button = BOOT_PIN;
4444

4545
ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
4646

47+
volatile bool otaRunning = false;
48+
49+
/********************* Callbacks *************************/
50+
void otaActiveCallback(bool otaActive) {
51+
otaRunning = otaActive;
52+
if (otaActive) {
53+
Serial.println("OTA started");
54+
} else {
55+
Serial.println("OTA finished");
56+
}
57+
}
58+
4759
/********************* RGB LED functions **************************/
4860
void setLED(bool value) {
4961
digitalWrite(led, value);
@@ -69,6 +81,9 @@ void setup() {
6981
// Add OTA client to the light bulb
7082
zbLight.addOTAClient(OTA_UPGRADE_RUNNING_FILE_VERSION, OTA_UPGRADE_DOWNLOADED_FILE_VERSION, OTA_UPGRADE_HW_VERSION);
7183

84+
// Optional: Register callback for OTA state change
85+
zbLight.onOTAStateChange(otaActiveCallback);
86+
7287
// Add endpoint to Zigbee Core
7388
Serial.println("Adding ZigbeeLight endpoint to Zigbee Core");
7489
Zigbee.addEndpoint(&zbLight);
@@ -99,6 +114,10 @@ void loop() {
99114
while (digitalRead(button) == LOW) {
100115
delay(50);
101116
if ((millis() - startTime) > 3000) {
117+
if (otaRunning) {
118+
Serial.println("OTA in progress, cannot reset now");
119+
break;
120+
}
102121
// If key pressed for more than 3secs, factory reset Zigbee and reboot
103122
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
104123
delay(1000);

libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
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

5246
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
5347

54-
volatile bool otaInhibitSleep = false;
5548
uint8_t dataToSend = 2; // Temperature and humidity values are reported in same endpoint, so 2 values are reported
5649
bool 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 *****************************/
9377
static 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

Comments
 (0)