Skip to content

Commit 10c6155

Browse files
authored
Update Zigbee_On_Off_Light.ino
1 parent c980602 commit 10c6155

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

examples/arduino-zigbee-light/src/Zigbee_On_Off_Light.ino

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ void setLED(bool value) {
4545

4646
/********************* Arduino functions **************************/
4747
void setup() {
48+
Serial.begin(115200);
49+
while (!Serial) {
50+
delay(10);
51+
}
4852
// Init LED and turn it OFF (if LED_PIN == RGB_BUILTIN, the rgbLedWrite() will be used under the hood)
4953
pinMode(LED_PIN, OUTPUT);
5054
digitalWrite(LED_PIN, LOW);
@@ -59,12 +63,21 @@ void setup() {
5963
zbLight.onLightChange(setLED);
6064

6165
//Add endpoint to Zigbee Core
62-
log_d("Adding ZigbeeLight endpoint to Zigbee Core");
66+
Serial.println("Adding ZigbeeLight endpoint to Zigbee Core");
6367
Zigbee.addEndpoint(&zbLight);
6468

6569
// When all EPs are registered, start Zigbee. By default acts as ZIGBEE_END_DEVICE
66-
log_d("Calling Zigbee.begin()");
67-
Zigbee.begin();
70+
if (!Zigbee.begin()) {
71+
Serial.println("Zigbee failed to start!");
72+
Serial.println("Rebooting...");
73+
ESP.restart();
74+
}
75+
Serial.println("Connecting to network");
76+
while (!Zigbee.connected()) {
77+
Serial.print(".");
78+
delay(100);
79+
}
80+
Serial.println();
6881
}
6982

7083
void loop() {
@@ -77,10 +90,13 @@ void loop() {
7790
delay(50);
7891
if ((millis() - startTime) > 3000) {
7992
// If key pressed for more than 3secs, factory reset Zigbee and reboot
80-
Serial.printf("Resetting Zigbee to factory settings, reboot.\n");
93+
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
94+
delay(1000);
8195
Zigbee.factoryReset();
8296
}
8397
}
98+
// Toggle light by pressing the button
99+
zbLight.setLight(!zbLight.getLightState());
84100
}
85101
delay(100);
86102
}

0 commit comments

Comments
 (0)