Update Zigbee_On_Off_Switch.ino

This commit is contained in:
Jason2866
2024-11-28 12:29:14 +01:00
committed by GitHub
parent 7d0916030e
commit c980602b63
@@ -70,6 +70,7 @@ ZigbeeSwitch zbSwitch = ZigbeeSwitch(SWITCH_ENDPOINT_NUMBER);
static void onZbButton(SwitchData *button_func_pair) { static void onZbButton(SwitchData *button_func_pair) {
if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) { if (button_func_pair->func == SWITCH_ONOFF_TOGGLE_CONTROL) {
// Send toggle command to the light // Send toggle command to the light
Serial.println("Toggling light");
zbSwitch.lightToggle(); zbSwitch.lightToggle();
} }
} }
@@ -93,7 +94,6 @@ static void enableGpioInterrupt(bool enabled) {
/********************* Arduino functions **************************/ /********************* Arduino functions **************************/
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
while (!Serial) { while (!Serial) {
delay(10); delay(10);
@@ -106,7 +106,7 @@ void setup() {
zbSwitch.allowMultipleBinding(true); zbSwitch.allowMultipleBinding(true);
//Add endpoint to Zigbee Core //Add endpoint to Zigbee Core
log_d("Adding ZigbeeSwitch endpoint to Zigbee Core"); Serial.println("Adding ZigbeeSwitch endpoint to Zigbee Core");
Zigbee.addEndpoint(&zbSwitch); Zigbee.addEndpoint(&zbSwitch);
//Open network for 180 seconds after boot //Open network for 180 seconds after boot
@@ -118,19 +118,22 @@ void setup() {
/* create a queue to handle gpio event from isr */ /* create a queue to handle gpio event from isr */
gpio_evt_queue = xQueueCreate(10, sizeof(SwitchData)); gpio_evt_queue = xQueueCreate(10, sizeof(SwitchData));
if (gpio_evt_queue == 0) { if (gpio_evt_queue == 0) {
log_e("Queue was not created and must not be used"); Serial.println("Queue creating failed, rebooting...");
while (1); ESP.restart();
} }
attachInterruptArg(buttonFunctionPair[i].pin, onGpioInterrupt, (void *)(buttonFunctionPair + i), FALLING); attachInterruptArg(buttonFunctionPair[i].pin, onGpioInterrupt, (void *)(buttonFunctionPair + i), FALLING);
} }
// When all EPs are registered, start Zigbee with ZIGBEE_COORDINATOR mode // When all EPs are registered, start Zigbee with ZIGBEE_COORDINATOR mode
log_d("Calling Zigbee.begin()"); if (!Zigbee.begin(ZIGBEE_COORDINATOR)) {
Zigbee.begin(ZIGBEE_COORDINATOR); Serial.println("Zigbee failed to start!");
Serial.println("Rebooting...");
ESP.restart();
}
Serial.println("Waiting for Light to bound to the switch"); Serial.println("Waiting for Light to bound to the switch");
//Wait for switch to bound to a light: //Wait for switch to bound to a light:
while (!zbSwitch.isBound()) { while (!zbSwitch.bound()) {
Serial.printf("."); Serial.printf(".");
delay(500); delay(500);
} }