Skip to content

Commit 526395c

Browse files
committed
fix(zigbee): Increase timeout, commision again on failure
1 parent eb1933f commit 526395c

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Diff for: libraries/Zigbee/src/ZigbeeCore.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "ZigbeeHandlers.cpp"
77
#include "Arduino.h"
88

9-
#define ZB_INIT_TIMEOUT 10000 // 10 seconds
9+
#define ZB_INIT_TIMEOUT 30000 // 30 seconds
1010

1111
extern "C" void zb_set_ed_node_descriptor(bool power_src, bool rx_on_when_idle, bool alloc_addr);
1212
static bool edBatteryPowered = false;
@@ -20,6 +20,7 @@ ZigbeeCore::ZigbeeCore() {
2020
_scan_status = ZB_SCAN_FAILED;
2121
_started = false;
2222
_connected = false;
23+
_scan_duration = 4; // maximum scan duration
2324
if (!lock) {
2425
lock = xSemaphoreCreateBinary();
2526
if (lock == NULL) {
@@ -90,6 +91,8 @@ void ZigbeeCore::addEndpoint(ZigbeeEP *ep) {
9091
}
9192

9293
static void esp_zb_task(void *pvParameters) {
94+
esp_zb_bdb_set_scan_duration(Zigbee.getScanDuration());
95+
9396
/* initialize Zigbee stack */
9497
ESP_ERROR_CHECK(esp_zb_start(false));
9598

@@ -178,6 +181,14 @@ void ZigbeeCore::setPrimaryChannelMask(uint32_t mask) {
178181
_primary_channel_mask = mask;
179182
}
180183

184+
void ZigbeeCore::setScanDuration(uint8_t duration) {
185+
if(duration < 1 || duration > 4) {
186+
log_e("Invalid scan duration, must be between 1 and 4");
187+
return;
188+
}
189+
_scan_duration = duration;
190+
}
191+
181192
void ZigbeeCore::setRebootOpenNetwork(uint8_t time) {
182193
_open_network = time;
183194
}
@@ -235,8 +246,8 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
235246
}
236247
} else {
237248
/* commissioning failed */
238-
log_e("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status));
239-
xSemaphoreGive(Zigbee.lock);
249+
log_w("Commissioning failed, trying again...", esp_err_to_name(err_status));
250+
esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_INITIALIZATION, 500);
240251
}
241252
break;
242253
case ESP_ZB_BDB_SIGNAL_FORMATION: // Coordinator

Diff for: libraries/Zigbee/src/ZigbeeCore.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ZigbeeCore {
6666
esp_zb_host_config_t _host_config;
6767
uint32_t _primary_channel_mask;
6868
int16_t _scan_status;
69+
uint8_t _scan_duration;
6970

7071
esp_zb_ep_list_t *_zb_ep_list;
7172
zigbee_role_t _role;
@@ -109,7 +110,12 @@ class ZigbeeCore {
109110
void setHostConfig(esp_zb_host_config_t config);
110111
esp_zb_host_config_t getHostConfig();
111112

112-
void setPrimaryChannelMask(uint32_t mask);
113+
void setPrimaryChannelMask(uint32_t mask); // By default all channels are scanned (11-26) -> mask 0x07FFF800
114+
void setScanDuration(uint8_t duration); // Can be set from 1 - 4. 1 is fastest, 4 is slowest
115+
uint8_t getScanDuration() {
116+
return _scan_duration;
117+
}
118+
113119
void setRebootOpenNetwork(uint8_t time);
114120
void openNetwork(uint8_t time);
115121

0 commit comments

Comments
 (0)