Skip to content

Commit 2e57aa4

Browse files
committed
fix(example): Use task for measure and sleep
1 parent f10ca9f commit 2e57aa4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status){
7474
#endif
7575

7676
/************************ Temp sensor *****************************/
77-
void meausureAndSleep() {
77+
static void meausureAndSleep(void *arg) {
7878
// Measure temperature sensor value
7979
float temperature = temperatureRead();
8080

@@ -93,6 +93,7 @@ void meausureAndSleep() {
9393
unsigned long startTime = millis();
9494
const unsigned long timeout = REPORT_TIMEOUT;
9595

96+
Serial.printf("Waiting for data report to be confirmed \r\n");
9697
// Wait until data was succesfully sent
9798
while(dataToSend != 0){
9899
if(resend){
@@ -105,6 +106,8 @@ void meausureAndSleep() {
105106
Serial.println("Report timeout!");
106107
break;
107108
}
109+
Serial.printf(".");
110+
delay(50); // 50ms delay to avoid busy-waiting
108111
}
109112

110113
// Put device to deep sleep after data was sent successfully or timeout
@@ -172,6 +175,9 @@ void setup() {
172175
}
173176
Serial.println();
174177
Serial.println("Successfully connected to Zigbee network");
178+
179+
// Start Temperature sensor reading task
180+
xTaskCreate(meausureAndSleep, "temp_sensor_update", 2048, NULL, 10, NULL);
175181
}
176182

177183
void loop() {
@@ -194,7 +200,5 @@ void loop() {
194200
}
195201
}
196202
}
197-
198-
// Call the function to measure temperature and put the device to sleep
199-
meausureAndSleep();
203+
delay(100);
200204
}

0 commit comments

Comments
 (0)