Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(zigbee): Increase timeout, commision again on failure + setScanDuration #10651

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions libraries/Zigbee/src/ZigbeeCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "ZigbeeHandlers.cpp"
#include "Arduino.h"

#define ZB_INIT_TIMEOUT 10000 // 10 seconds
#define ZB_INIT_TIMEOUT 30000 // 30 seconds

extern "C" void zb_set_ed_node_descriptor(bool power_src, bool rx_on_when_idle, bool alloc_addr);
static bool edBatteryPowered = false;
Expand All @@ -20,6 +20,7 @@ ZigbeeCore::ZigbeeCore() {
_scan_status = ZB_SCAN_FAILED;
_started = false;
_connected = false;
_scan_duration = 4; // maximum scan duration
if (!lock) {
lock = xSemaphoreCreateBinary();
if (lock == NULL) {
Expand Down Expand Up @@ -90,6 +91,8 @@ void ZigbeeCore::addEndpoint(ZigbeeEP *ep) {
}

static void esp_zb_task(void *pvParameters) {
esp_zb_bdb_set_scan_duration(Zigbee.getScanDuration());

/* initialize Zigbee stack */
ESP_ERROR_CHECK(esp_zb_start(false));

Expand Down Expand Up @@ -178,6 +181,14 @@ void ZigbeeCore::setPrimaryChannelMask(uint32_t mask) {
_primary_channel_mask = mask;
}

void ZigbeeCore::setScanDuration(uint8_t duration) {
if(duration < 1 || duration > 4) {
log_e("Invalid scan duration, must be between 1 and 4");
return;
}
_scan_duration = duration;
}

void ZigbeeCore::setRebootOpenNetwork(uint8_t time) {
_open_network = time;
}
Expand Down Expand Up @@ -235,8 +246,8 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
}
} else {
/* commissioning failed */
log_e("Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status));
xSemaphoreGive(Zigbee.lock);
log_w("Commissioning failed, trying again...", esp_err_to_name(err_status));
esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_INITIALIZATION, 500);
}
break;
case ESP_ZB_BDB_SIGNAL_FORMATION: // Coordinator
Expand Down
8 changes: 7 additions & 1 deletion libraries/Zigbee/src/ZigbeeCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ZigbeeCore {
esp_zb_host_config_t _host_config;
uint32_t _primary_channel_mask;
int16_t _scan_status;
uint8_t _scan_duration;

esp_zb_ep_list_t *_zb_ep_list;
zigbee_role_t _role;
Expand Down Expand Up @@ -109,7 +110,12 @@ class ZigbeeCore {
void setHostConfig(esp_zb_host_config_t config);
esp_zb_host_config_t getHostConfig();

void setPrimaryChannelMask(uint32_t mask);
void setPrimaryChannelMask(uint32_t mask); // By default all channels are scanned (11-26) -> mask 0x07FFF800
void setScanDuration(uint8_t duration); // Can be set from 1 - 4. 1 is fastest, 4 is slowest
uint8_t getScanDuration() {
return _scan_duration;
}

void setRebootOpenNetwork(uint8_t time);
void openNetwork(uint8_t time);

Expand Down
Loading