Skip to content

Commit c980602

Browse files
authored
Update Zigbee_On_Off_Switch.ino
1 parent 7d09160 commit c980602

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

examples/arduino-zigbee-switch/src/Zigbee_On_Off_Switch.ino

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ ZigbeeSwitch zbSwitch = ZigbeeSwitch(SWITCH_ENDPOINT_NUMBER);
7070
static void onZbButton(SwitchData *button_func_pair) {
7171
if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) {
7272
// Send toggle command to the light
73+
Serial.println("Toggling light");
7374
zbSwitch.lightToggle();
7475
}
7576
}
@@ -93,7 +94,6 @@ static void enableGpioInterrupt(bool enabled) {
9394

9495
/********************* Arduino functions **************************/
9596
void setup() {
96-
9797
Serial.begin(115200);
9898
while (!Serial) {
9999
delay(10);
@@ -106,7 +106,7 @@ void setup() {
106106
zbSwitch.allowMultipleBinding(true);
107107

108108
//Add endpoint to Zigbee Core
109-
log_d("Adding ZigbeeSwitch endpoint to Zigbee Core");
109+
Serial.println("Adding ZigbeeSwitch endpoint to Zigbee Core");
110110
Zigbee.addEndpoint(&zbSwitch);
111111

112112
//Open network for 180 seconds after boot
@@ -118,19 +118,22 @@ void setup() {
118118
/* create a queue to handle gpio event from isr */
119119
gpio_evt_queue = xQueueCreate(10, sizeof(SwitchData));
120120
if (gpio_evt_queue == 0) {
121-
log_e("Queue was not created and must not be used");
122-
while (1);
121+
Serial.println("Queue creating failed, rebooting...");
122+
ESP.restart();
123123
}
124124
attachInterruptArg(buttonFunctionPair[i].pin, onGpioInterrupt, (void *)(buttonFunctionPair + i), FALLING);
125125
}
126126

127127
// When all EPs are registered, start Zigbee with ZIGBEE_COORDINATOR mode
128-
log_d("Calling Zigbee.begin()");
129-
Zigbee.begin(ZIGBEE_COORDINATOR);
128+
if (!Zigbee.begin(ZIGBEE_COORDINATOR)) {
129+
Serial.println("Zigbee failed to start!");
130+
Serial.println("Rebooting...");
131+
ESP.restart();
132+
}
130133

131134
Serial.println("Waiting for Light to bound to the switch");
132135
//Wait for switch to bound to a light:
133-
while (!zbSwitch.isBound()) {
136+
while (!zbSwitch.bound()) {
134137
Serial.printf(".");
135138
delay(500);
136139
}

0 commit comments

Comments
 (0)