37
37
38
38
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
39
39
#define TIME_TO_SLEEP 55 /* Sleep for 55s will + 5s delay for establishing connection => data reported every 1 minute */
40
+ #define REPORT_TIMEOUT 30000 /* Timeout for reporting data in ms */
40
41
41
42
uint8_t button = BOOT_PIN;
42
43
@@ -57,10 +58,14 @@ void meausureAndSleep() {
57
58
zbTempSensor.setTemperature (temperature);
58
59
zbTempSensor.setHumidity (humidity);
59
60
61
+
60
62
// Report temperature and humidity values
61
63
zbTempSensor.report (); // reports temperature and humidity values (if humidity sensor is not added, only temperature is reported)
62
64
Serial.printf (" Reported temperature: %.2f°C, Humidity: %.2f%%\r\n " , temperature, humidity);
63
65
66
+ unsigned long startTime = millis ();
67
+ const unsigned long timeout = REPORT_TIMEOUT;
68
+
64
69
// Wait until data was succesfully sent
65
70
while (dataToSend != 0 ){
66
71
if (resend){
@@ -69,15 +74,19 @@ void meausureAndSleep() {
69
74
dataToSend = 2 ;
70
75
zbTempSensor.report (); // report again
71
76
}
77
+ if (millis () - startTime >= timeout) {
78
+ Serial.println (" Report timeout!" );
79
+ break ;
80
+ }
72
81
}
73
82
74
- // Put device to deep sleep after data was sent successfully
83
+ // Put device to deep sleep after data was sent successfully or timeout
75
84
Serial.println (" Going to sleep now" );
76
85
esp_deep_sleep_start ();
77
86
}
78
87
79
88
void onResponse (zb_cmd_type_t command, esp_zb_zcl_status_t status){
80
- Serial.printf (" Response status recieved %s" , zbTempSensor.esp_zb_zcl_status_to_name (status));
89
+ Serial.printf (" Response status received %s\r\n " , zbTempSensor.esp_zb_zcl_status_to_name (status));
81
90
if (command == ZB_CMD_REPORT_ATTRIBUTE){
82
91
switch (status){
83
92
case ESP_ZB_ZCL_STATUS_SUCCESS: dataToSend--; break ;
0 commit comments