6
6
#include " ZigbeeHandlers.cpp"
7
7
#include " Arduino.h"
8
8
9
- #define ZB_INIT_TIMEOUT 10000 // 10 seconds
9
+ #define ZB_INIT_TIMEOUT 30000 // 30 seconds
10
10
11
11
extern " C" void zb_set_ed_node_descriptor (bool power_src, bool rx_on_when_idle, bool alloc_addr);
12
12
static bool edBatteryPowered = false ;
@@ -20,6 +20,7 @@ ZigbeeCore::ZigbeeCore() {
20
20
_scan_status = ZB_SCAN_FAILED;
21
21
_started = false ;
22
22
_connected = false ;
23
+ _scan_duration = 4 ; // maximum scan duration
23
24
if (!lock) {
24
25
lock = xSemaphoreCreateBinary ();
25
26
if (lock == NULL ) {
@@ -90,6 +91,8 @@ void ZigbeeCore::addEndpoint(ZigbeeEP *ep) {
90
91
}
91
92
92
93
static void esp_zb_task (void *pvParameters) {
94
+ esp_zb_bdb_set_scan_duration (Zigbee.getScanDuration ());
95
+
93
96
/* initialize Zigbee stack */
94
97
ESP_ERROR_CHECK (esp_zb_start (false ));
95
98
@@ -178,6 +181,14 @@ void ZigbeeCore::setPrimaryChannelMask(uint32_t mask) {
178
181
_primary_channel_mask = mask;
179
182
}
180
183
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
+
181
192
void ZigbeeCore::setRebootOpenNetwork (uint8_t time) {
182
193
_open_network = time ;
183
194
}
@@ -235,8 +246,8 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
235
246
}
236
247
} else {
237
248
/* 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 );
240
251
}
241
252
break ;
242
253
case ESP_ZB_BDB_SIGNAL_FORMATION: // Coordinator
0 commit comments