@@ -74,7 +74,7 @@ void onResponse(zb_cmd_type_t command, esp_zb_zcl_status_t status){
74
74
#endif
75
75
76
76
/* *********************** Temp sensor *****************************/
77
- void meausureAndSleep () {
77
+ static void meausureAndSleep (void *arg ) {
78
78
// Measure temperature sensor value
79
79
float temperature = temperatureRead ();
80
80
@@ -93,6 +93,7 @@ void meausureAndSleep() {
93
93
unsigned long startTime = millis ();
94
94
const unsigned long timeout = REPORT_TIMEOUT;
95
95
96
+ Serial.printf (" Waiting for data report to be confirmed \r\n " );
96
97
// Wait until data was succesfully sent
97
98
while (dataToSend != 0 ){
98
99
if (resend){
@@ -105,6 +106,8 @@ void meausureAndSleep() {
105
106
Serial.println (" Report timeout!" );
106
107
break ;
107
108
}
109
+ Serial.printf (" ." );
110
+ delay (50 ); // 50ms delay to avoid busy-waiting
108
111
}
109
112
110
113
// Put device to deep sleep after data was sent successfully or timeout
@@ -172,6 +175,9 @@ void setup() {
172
175
}
173
176
Serial.println ();
174
177
Serial.println (" Successfully connected to Zigbee network" );
178
+
179
+ // Start Temperature sensor reading task
180
+ xTaskCreate (meausureAndSleep, " temp_sensor_update" , 2048 , NULL , 10 , NULL );
175
181
}
176
182
177
183
void loop () {
@@ -194,7 +200,5 @@ void loop() {
194
200
}
195
201
}
196
202
}
197
-
198
- // Call the function to measure temperature and put the device to sleep
199
- meausureAndSleep ();
203
+ delay (100 );
200
204
}
0 commit comments