27
27
*/
28
28
29
29
#ifndef ZIGBEE_MODE_ED
30
- #error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
30
+ #error "Zigbee end device mode is not selected in Tools->Zigbee mode"
31
31
#endif
32
32
33
33
#include " Zigbee.h"
@@ -56,14 +56,19 @@ void meausureAndSleep() {
56
56
zbTempSensor.reportTemperature ();
57
57
zbTempSensor.reportHumidity ();
58
58
59
- log_d ( " Temperature : %.2f°C, Humidity: %.2f%" , temperature, humidity);
59
+ Serial. printf ( " Reported temperature : %.2f°C, Humidity: %.2f%\n " , temperature, humidity);
60
60
61
61
// Put device to deep sleep
62
+ Serial.println (" Going to sleep now" );
62
63
esp_deep_sleep_start ();
63
64
}
64
65
65
66
/* ******************** Arduino functions **************************/
66
67
void setup () {
68
+ Serial.begin (115200 );
69
+ while (!Serial) {
70
+ delay (10 );
71
+ }
67
72
// Init button switch
68
73
pinMode (BUTTON_PIN, INPUT_PULLUP);
69
74
@@ -94,14 +99,20 @@ void setup() {
94
99
zigbeeConfig.nwk_cfg .zed_cfg .keep_alive = 10000 ;
95
100
96
101
// When all EPs are registered, start Zigbee in End Device mode
97
- Zigbee.begin (&zigbeeConfig, false );
98
-
99
- // Wait for Zigbee to start
100
- while (!Zigbee.isStarted ()) {
102
+ if (!Zigbee.begin (&zigbeeConfig, false )){
103
+ Serial.println (" Zigbee failed to start!" );
104
+ Serial.println (" Rebooting..." );
105
+ ESP.restart ();
106
+ }
107
+ Serial.println (" Connecting to network" );
108
+ while (!Zigbee.connected ()) {
109
+ Serial.print (" ." );
101
110
delay (100 );
102
111
}
112
+ Serial.println ();
113
+ Serial.println (" Sucessfully connected to Zigbee network" );
103
114
104
- // Delay 5s to allow establishing connection with coordinator, needed for sleepy devices
115
+ // Delay 5s (may be adjusted) to allow establishing proper connection with coordinator, needed for sleepy devices
105
116
delay (5000 );
106
117
}
107
118
@@ -115,7 +126,8 @@ void loop() {
115
126
delay (50 );
116
127
if ((millis () - startTime) > 3000 ) {
117
128
// If key pressed for more than 3secs, factory reset Zigbee and reboot
118
- Zigbee.factoryReset ();
129
+ Serial.println (" Resetting Zigbee to factory and rebooting in 1s." );
130
+ delay (1000 );
119
131
}
120
132
}
121
133
}
0 commit comments