From 2ede22bba488d090f25bf16c2eba1e05cf0c473f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:51:34 +0100 Subject: [PATCH] fix(zigbee): Check if device is not bound before bounding again --- libraries/Zigbee/src/ZigbeeCore.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/Zigbee/src/ZigbeeCore.cpp b/libraries/Zigbee/src/ZigbeeCore.cpp index cc0111f2644..d9477ec1f78 100644 --- a/libraries/Zigbee/src/ZigbeeCore.cpp +++ b/libraries/Zigbee/src/ZigbeeCore.cpp @@ -314,7 +314,20 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { // for each endpoint in the list call the findEndpoint function if not bounded or allowed to bind multiple devices for (std::list::iterator it = Zigbee.ep_objects.begin(); it != Zigbee.ep_objects.end(); ++it) { if (!(*it)->bound() || (*it)->epAllowMultipleBinding()) { - (*it)->findEndpoint(&cmd_req); + // Check if the device is already bound + bool found = false; + // Gte the list of devices bound to the EP + std::list bound_devices = (*it)->getBoundDevices(); + for (std::list::iterator device = bound_devices.begin(); device != bound_devices.end(); ++device) { + if (((*device)->short_addr == dev_annce_params->device_short_addr) || (memcmp((*device)->ieee_addr, dev_annce_params->ieee_addr, 8) == 0)) { + found = true; + log_d("Device already bound to endpoint %d", (*it)->getEndpoint()); + break; + } + } + if (!found) { + (*it)->findEndpoint(&cmd_req); + } } } }