-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Closed
Closed
Copy link
Labels
Area: ZigbeeIssues and Feature Request about ZigbeeIssues and Feature Request about ZigbeeType: For referenceCommon questions & problemsCommon questions & problemsType: QuestionOnly questionOnly question
Description
Board
ESP32-C6
Device Description
Dev module
Hardware Configuration
Base setting
Version
v3.1.0
IDE Name
Arduino IDE 2.3.4
Operating System
Windows11
Flash frequency
80Mhz
PSRAM enabled
no
Upload speed
115200
Description
Hello,
I am using the Zigbee_On_Off_Switch example for Arduino with the ESP32-C6 module.
I successfully integrated the wall light switches from Tuya and other manufacturers, and the switch On/Off works fine. However, the wall light switch I have is a 3-gang switch.
The first switch works well with Zigbee_On_Off_Switch, but how should I get the second and third switches to work?
I am new to Zigbee and am having difficulty understanding how to set it up.
Sketch
#ifndef ZIGBEE_MODE_ZCZR
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
#endif
#include "Zigbee.h"
/* Zigbee switch configuration */
#define SWITCH_ENDPOINT_NUMBER 5
uint8_t buttonPin = BOOT_PIN;
ZigbeeSwitch zbSwitch = ZigbeeSwitch(SWITCH_ENDPOINT_NUMBER);
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
/********************* Arduino functions **************************/
void setup() {
Serial.begin(115200);
//Init button switch
pinMode(buttonPin, INPUT_PULLUP);
//Optional: set Zigbee device name and model
zbSwitch.setManufacturerAndModel("SPACETALK", "ZigbeeWALLSwitch");
//Optional to allow multiple light to bind to the switch
zbSwitch.allowMultipleBinding(false);
//Add endpoint to Zigbee Core
Serial.println("Adding ZigbeeSwitch endpoint to Zigbee Core");
Zigbee.addEndpoint(&zbSwitch);
//Open network for 180 seconds after boot
Zigbee.setRebootOpenNetwork(180);
// When all EPs are registered, start Zigbee with ZIGBEE_COORDINATOR mode
if (!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");
//Wait for switch to bound to a light:
while (!zbSwitch.bound()) {
Serial.printf(".");
delay(500);
}
Serial.println();
// Optional: List all bound devices and read manufacturer and model name
std::list<zb_device_params_t *> boundLights = zbSwitch.getBoundDevices();
for (const auto &device : boundLights) {
Serial.printf("Device on endpoint %d, short address: 0x%x\r\n", device->endpoint, device->short_addr);
Serial.printf(
"IEEE Address: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\r\n", device->ieee_addr[7], device->ieee_addr[6], device->ieee_addr[5], device->ieee_addr[4],
device->ieee_addr[3], device->ieee_addr[2], device->ieee_addr[1], device->ieee_addr[0]
);
char *manufacturer = zbSwitch.readManufacturer(device->endpoint, device->short_addr, device->ieee_addr);
char *model = zbSwitch.readModel(device->endpoint, device->short_addr, device->ieee_addr);
if (manufacturer != nullptr) {
Serial.printf("Light manufacturer: %s\r\n", manufacturer);
}
if (model != nullptr) {
Serial.printf("Light model: %s\r\n", model);
}
}
Serial.println(" ---- END SETUP ----");
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
// Toggle light
Serial.println(" --> BTN Input : Light Toggle");
zbSwitch.lightToggle();
}
}
}
lastButtonState = reading;
if (Serial.available()) {
String command = Serial.readStringUntil('\n');
Serial.print(" SIG IN : ");
Serial.println(command);
if (command == "on") {
Serial.println(" --> SIG Input : Light ON");
zbSwitch.lightOn();
} else if (command == "off") {
Serial.println(" --> SIG Input : Light OFF");
zbSwitch.lightOff();
} else if (command == "freset") {
Serial.println(" --> SIG Input : Factory Reset!");
delay(1500);
Zigbee.factoryReset();
}
}
static uint32_t last_print = 0;
if (millis() - last_print > 30000) {
last_print = millis();
zbSwitch.printBoundDevices(Serial);
}
}Debug Message
18:54:18.029 -> Adding ZigbeeSwitch endpoint to Zigbee Core
18:54:18.029 -> [ 509][D][ZigbeeCore.cpp:84] addEndpoint(): Endpoint: 5, Device ID: 0x0000
18:54:18.029 -> [ 520][D][ZigbeeCore.cpp:123] zigbeeInit(): Initialize Zigbee stack
18:54:18.106 -> [ 612][D][ZigbeeCore.cpp:130] zigbeeInit(): Register all Zigbee EPs in list
18:54:18.143 -> [ 620][I][ZigbeeCore.cpp:138] zigbeeInit(): List of registered Zigbee EPs:
18:54:18.143 -> [ 626][I][ZigbeeCore.cpp:140] zigbeeInit(): Device type: General On/Off switch, Endpoint: 5, Device ID: 0x0000
18:54:18.143 -> [ 643][V][ZigbeeCore.cpp:352] esp_zb_app_signal_handler(): ZDO signal: ZDO Config Ready (0x17), status: ESP_FAIL
18:54:18.143 -> [ 653][I][ZigbeeCore.cpp:219] esp_zb_app_signal_handler(): Zigbee stack initialized
18:54:18.179 -> [ 667][I][ZigbeeCore.cpp:341] esp_zb_app_signal_handler(): Network(0xca17) closed, devices joining not allowed.
18:54:18.179 -> [ 678][I][ZigbeeCore.cpp:225] esp_zb_app_signal_handler(): Device started up in non factory-reset mode
18:54:18.179 -> [ 688][I][ZigbeeCore.cpp:238] esp_zb_app_signal_handler(): Device rebooted
18:54:18.212 -> [ 695][I][ZigbeeCore.cpp:242] esp_zb_app_signal_handler(): Opening network for joining for 180 seconds
18:54:18.212 -> [ 704][D][ZigbeeCore.cpp:479] searchBindings(): Requesting binding table for address 0x0000
18:54:18.212 -> [ 713][D][ZigbeeCore.cpp:419] bindingTableCb(): Binding table callback for address 0x0000 with status 0
18:54:18.247 -> [ 723][D][ZigbeeCore.cpp:422] bindingTableCb(): Binding table info: total 1, index 0, count 1
18:54:18.247 -> [ 731][D][ZigbeeCore.cpp:432] bindingTableCb(): Binding table record: src_endp 5, dst_endp 1, cluster_id 0x0006, dst_addr_mode 3
18:54:18.247 -> [ 743][D][ZigbeeCore.cpp:449] bindingTableCb(): Device bound to EP 5 -> device endpoint: 1, short addr: 0x0000, ieee addr: DC:8E:95:FF:FE:E1:18:D2
18:54:18.247 -> [ 756][D][ZigbeeCore.cpp:470] bindingTableCb(): Filling bounded devices finished
18:54:18.289 -> Waiting for Light to bound to the switch
18:54:18.289 ->
18:54:18.289 -> Device on endpoint 1, short address: 0x0
18:54:18.289 -> IEEE Address: DC:8E:95:FF:FE:E1:18:D2
18:54:18.335 -> [ 810][I][ZigbeeCore.cpp:339] esp_zb_app_signal_handler(): Network(0xca17) is open for 180 seconds
18:54:18.368 -> [ 869][V][ZigbeeHandlers.cpp:82] zb_cmd_read_attr_resp_handler(): Read attribute response: from address(0x2dd8) src endpoint(1) to dst endpoint(5) cluster(0x0)
18:54:18.413 -> [ 883][V][ZigbeeHandlers.cpp:91] zb_cmd_read_attr_resp_handler(): Read attribute response: status(0), cluster(0x0), attribute(0x4), type(0x42), value(9)
18:54:18.413 -> [ 897][I][ZigbeeEP.cpp:218] zbReadBasicCluster(): Peer Manufacturer is "DAWON_DNS"
18:54:18.492 -> [ 974][V][ZigbeeHandlers.cpp:82] zb_cmd_read_attr_resp_handler(): Read attribute response: from address(0x2dd8) src endpoint(1) to dst endpoint(5) cluster(0x0)
18:54:18.492 -> [ 988][V][ZigbeeHandlers.cpp:91] zb_cmd_read_attr_resp_handler(): Read attribute response: status(0), cluster(0x0), attribute(0x5), type(0x42), value(10)
18:54:18.523 -> [ 1002][I][ZigbeeEP.cpp:227] zbReadBasicCluster(): Peer Model is "PM-S350-ZB"
18:54:18.523 -> Light manufacturer: DAWON_DNS
18:54:18.523 -> Light model: PM-S350-ZB
18:54:18.523 -> ---- END SETUP ----
18:54:18.523 -> =========== After Setup Start ============
18:54:18.523 -> INTERNAL Memory Info:
18:54:18.523 -> ------------------------------------------
18:54:18.523 -> Total Size : 448396 B ( 437.9 KB)
18:54:18.557 -> Free Bytes : 381212 B ( 372.3 KB)
18:54:18.557 -> Allocated Bytes : 59032 B ( 57.6 KB)
18:54:18.557 -> Minimum Free Bytes: 381184 B ( 372.2 KB)
18:54:18.557 -> Largest Free Block: 352244 B ( 344.0 KB)
18:54:18.557 -> ------------------------------------------
18:54:18.557 -> GPIO Info:
18:54:18.557 -> ------------------------------------------
18:54:18.557 -> GPIO : BUS_TYPE[bus/unit][chan]
18:54:18.557 -> --------------------------------------
18:54:18.557 -> 9 : GPIO
18:54:18.557 -> 16 : UART_TX[0]
18:54:18.599 -> 17 : UART_RX[0]
18:54:18.599 -> ============ After Setup End =============
18:54:18.689 -> --> BTN Input : Light Toggle
18:54:18.689 -> [ 1149][V][ZigbeeSwitch.cpp:72] lightToggle(): Sending 'light toggle' command
18:54:18.721 -> [ 1217][V][ZigbeeHandlers.cpp:134] zb_cmd_default_resp_handler(): Received default response: from address(0x2dd8), src_endpoint(1) to dst_endpoint(5), cluster(0x6) with status 0x81
18:54:40.404 -> SIG IN : on
18:54:40.404 -> --> SIG Input : Light ON
18:54:40.404 -> [ 22905][V][ZigbeeSwitch.cpp:140] lightOn(): Sending 'light on' command
18:54:40.481 -> [ 22976][V][ZigbeeHandlers.cpp:134] zb_cmd_default_resp_handler(): Received default response: from address(0x2dd8), src_endpoint(1) to dst_endpoint(5), cluster(0x6) with status 0x0
18:54:42.246 -> SIG IN : off
18:54:42.246 -> --> SIG Input : Light OFF
18:54:42.246 -> [ 24717][V][ZigbeeSwitch.cpp:208] lightOff(): Sending 'light off' command
18:54:42.283 -> [ 24789][V][ZigbeeHandlers.cpp:134] zb_cmd_default_resp_handler(): Received default response: from address(0x2dd8), src_endpoint(1) to dst_endpoint(5), cluster(0x6) with status 0x0
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
Labels
Area: ZigbeeIssues and Feature Request about ZigbeeIssues and Feature Request about ZigbeeType: For referenceCommon questions & problemsCommon questions & problemsType: QuestionOnly questionOnly question