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
1111extern " C" void zb_set_ed_node_descriptor (bool power_src, bool rx_on_when_idle, bool alloc_addr);
1212static 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
9293static 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+
181192void 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
0 commit comments