From b69365447bb1d4575fd5ffe80f14a5b52bcda5f7 Mon Sep 17 00:00:00 2001 From: "xieqinan@espressif.com" Date: Thu, 19 Dec 2024 11:51:44 +0800 Subject: [PATCH 1/2] feat(app): added retry mechanism when device startup failed --- components/esp-zigbee-ncp/src/esp_ncp_zb.c | 4 +++- .../HA_color_dimmable_light/main/esp_zb_light.c | 7 +++++-- .../HA_color_dimmable_switch/main/esp_zb_switch.c | 7 +++++-- .../HA_on_off_light/main/esp_zb_light.c | 8 +++++--- .../HA_on_off_switch/main/esp_zb_switch.c | 7 +++++-- .../main/esp_zb_temperature_sensor.c | 8 +++++--- .../HA_thermostat/main/esp_zb_thermostat.c | 7 +++++-- .../main/esp_zigbee_all_device_types_app.c | 5 +++-- .../customized_server/main/esp_HA_customized_light.c | 7 +++++-- examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c | 7 +++++-- .../esp_zigbee_gpc/main/esp_zigbee_gpc.c | 7 +++++-- examples/esp_zigbee_host/main/esp_zb_host.c | 5 ++++- examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c | 7 +++++-- examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c | 7 +++++-- .../deep_sleep/main/esp_zb_sleepy_end_device.c | 9 +++++---- .../light_sleep/main/esp_zb_sleepy_end_device.c | 8 +++++--- .../touchlink_light/main/esp_touchlink_light.c | 6 ++++-- .../touchlink_switch/main/esp_touchlink_switch.c | 6 ++++-- 18 files changed, 83 insertions(+), 39 deletions(-) diff --git a/components/esp-zigbee-ncp/src/esp_ncp_zb.c b/components/esp-zigbee-ncp/src/esp_ncp_zb.c index fa884e4..ad9d492 100644 --- a/components/esp-zigbee-ncp/src/esp_ncp_zb.c +++ b/components/esp-zigbee-ncp/src/esp_ncp_zb.c @@ -577,7 +577,9 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + esp_err_to_name(err_status)); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); } break; case ESP_ZB_BDB_SIGNAL_TOUCHLINK_NWK_STARTED: diff --git a/examples/esp_zigbee_HA_sample/HA_color_dimmable_light/main/esp_zb_light.c b/examples/esp_zigbee_HA_sample/HA_color_dimmable_light/main/esp_zb_light.c index adf9c81..6c98d76 100644 --- a/examples/esp_zigbee_HA_sample/HA_color_dimmable_light/main/esp_zb_light.c +++ b/examples/esp_zigbee_HA_sample/HA_color_dimmable_light/main/esp_zb_light.c @@ -51,7 +51,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network steering"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); @@ -59,7 +59,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGW(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_STEERING: diff --git a/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c b/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c index b6e4c1c..4a4e287 100644 --- a/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c +++ b/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c @@ -144,7 +144,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); @@ -153,7 +153,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_FORMATION: diff --git a/examples/esp_zigbee_HA_sample/HA_on_off_light/main/esp_zb_light.c b/examples/esp_zigbee_HA_sample/HA_on_off_light/main/esp_zb_light.c index 7070568..d6cad96 100644 --- a/examples/esp_zigbee_HA_sample/HA_on_off_light/main/esp_zb_light.c +++ b/examples/esp_zigbee_HA_sample/HA_on_off_light/main/esp_zb_light.c @@ -50,7 +50,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network steering"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); @@ -58,8 +58,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - /* commissioning failed */ - ESP_LOGW(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_STEERING: diff --git a/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c b/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c index ee46164..d4a7204 100644 --- a/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c +++ b/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c @@ -112,7 +112,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); @@ -121,7 +121,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_FORMATION: diff --git a/examples/esp_zigbee_HA_sample/HA_temperature_sensor/main/esp_zb_temperature_sensor.c b/examples/esp_zigbee_HA_sample/HA_temperature_sensor/main/esp_zb_temperature_sensor.c index 3272f69..d27d786 100644 --- a/examples/esp_zigbee_HA_sample/HA_temperature_sensor/main/esp_zb_temperature_sensor.c +++ b/examples/esp_zigbee_HA_sample/HA_temperature_sensor/main/esp_zb_temperature_sensor.c @@ -97,7 +97,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network steering"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); @@ -105,8 +105,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - /* commissioning failed */ - ESP_LOGW(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_STEERING: diff --git a/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c b/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c index a5c2b9a..c92b3e7 100644 --- a/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c +++ b/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c @@ -227,7 +227,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); @@ -236,7 +236,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_FORMATION: diff --git a/examples/esp_zigbee_all_device_types_app/main/esp_zigbee_all_device_types_app.c b/examples/esp_zigbee_all_device_types_app/main/esp_zigbee_all_device_types_app.c index 322ec4c..8a92d93 100644 --- a/examples/esp_zigbee_all_device_types_app/main/esp_zigbee_all_device_types_app.c +++ b/examples/esp_zigbee_all_device_types_app/main/esp_zigbee_all_device_types_app.c @@ -38,9 +38,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", err_name); + ESP_LOGE(TAG, "%s failed with status: %s, please retry", esp_zb_zdo_signal_to_string(sig_type), + esp_err_to_name(err_status)); } break; case ESP_ZB_BDB_SIGNAL_FORMATION: diff --git a/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c b/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c index 17dd1e9..af546bd 100644 --- a/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c +++ b/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c @@ -49,7 +49,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); @@ -58,7 +58,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_FORMATION: diff --git a/examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c b/examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c index 2ae3267..99a24de 100644 --- a/examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c +++ b/examples/esp_zigbee_gateway/main/esp_zigbee_gateway.c @@ -139,7 +139,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); @@ -148,7 +148,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_FORMATION: diff --git a/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c b/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c index 899e640..743f05b 100644 --- a/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c +++ b/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c @@ -101,7 +101,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); @@ -110,7 +110,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_FORMATION: diff --git a/examples/esp_zigbee_host/main/esp_zb_host.c b/examples/esp_zigbee_host/main/esp_zb_host.c index d16acbf..edeb585 100644 --- a/examples/esp_zigbee_host/main/esp_zb_host.c +++ b/examples/esp_zigbee_host/main/esp_zb_host.c @@ -109,7 +109,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_FORMATION: diff --git a/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c b/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c index 1333cc0..5270ff0 100644 --- a/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c +++ b/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c @@ -89,7 +89,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network steering"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); @@ -97,7 +97,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_STEERING: diff --git a/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c b/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c index 38fb0fa..f49c863 100644 --- a/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c +++ b/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c @@ -88,7 +88,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network formation"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION); @@ -97,7 +97,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_FORMATION: diff --git a/examples/esp_zigbee_sleep/deep_sleep/main/esp_zb_sleepy_end_device.c b/examples/esp_zigbee_sleep/deep_sleep/main/esp_zb_sleepy_end_device.c index 67f78ad..c366ef1 100644 --- a/examples/esp_zigbee_sleep/deep_sleep/main/esp_zb_sleepy_end_device.c +++ b/examples/esp_zigbee_sleep/deep_sleep/main/esp_zb_sleepy_end_device.c @@ -142,7 +142,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START: case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network steering"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); @@ -151,9 +151,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - /* commissioning failed */ - ESP_LOGW(TAG, "Failed to initialize Zigbee stack (status: %d)", err_status); - esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_STEERING: diff --git a/examples/esp_zigbee_sleep/light_sleep/main/esp_zb_sleepy_end_device.c b/examples/esp_zigbee_sleep/light_sleep/main/esp_zb_sleepy_end_device.c index 1f2b1dc..ca6b545 100644 --- a/examples/esp_zigbee_sleep/light_sleep/main/esp_zb_sleepy_end_device.c +++ b/examples/esp_zigbee_sleep/light_sleep/main/esp_zb_sleepy_end_device.c @@ -107,7 +107,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { ESP_LOGI(TAG, "Start network steering"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); @@ -115,8 +115,10 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - /* commissioning failed */ - ESP_LOGW(TAG, "Failed to initialize Zigbee stack (status: %d)", err_status); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + 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, 1000); } break; case ESP_ZB_BDB_SIGNAL_STEERING: diff --git a/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c b/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c index d1d2ed7..0b7e615 100644 --- a/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c +++ b/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c @@ -48,14 +48,16 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_TOUCHLINK_TARGET); } else { ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGW(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + esp_err_to_name(err_status)); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); } break; case ESP_ZB_BDB_SIGNAL_TOUCHLINK_TARGET: diff --git a/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c b/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c index dcc5bbe..499c899 100644 --- a/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c +++ b/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c @@ -140,7 +140,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT: if (err_status == ESP_OK) { ESP_LOGI(TAG, "Deferred driver initialization %s", deferred_driver_init() ? "failed" : "successful"); - ESP_LOGI(TAG, "Device started up in %s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non"); + ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non"); if (esp_zb_bdb_is_factory_new()) { esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_TOUCHLINK_COMMISSIONING); ESP_LOGI(TAG, "Scanning as a Touchlink initiator..."); @@ -148,7 +148,9 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) ESP_LOGI(TAG, "Device rebooted"); } } else { - ESP_LOGW(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status)); + ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type), + esp_err_to_name(err_status)); + esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION); } break; case ESP_ZB_BDB_SIGNAL_TOUCHLINK_NWK_STARTED: From dba7ed8ef29bb2d53b622e233963a6d0f9628fea Mon Sep 17 00:00:00 2001 From: "xieqinan@espressif.com" Date: Thu, 19 Dec 2024 16:42:09 +0800 Subject: [PATCH 2/2] feat(app): ensure the deferred driver will not been inited repeatedly --- .../main/esp_zb_light.c | 8 +++-- .../main/esp_zb_switch.c | 10 +++++-- .../HA_on_off_light/main/esp_zb_light.c | 8 +++-- .../HA_on_off_switch/main/esp_zb_switch.c | 10 +++++-- .../main/esp_zb_temperature_sensor.c | 15 ++++++---- .../HA_thermostat/main/esp_zb_thermostat.c | 11 +++++-- .../main/esp_HA_customized_switch.c | 10 +++++-- .../main/esp_HA_customized_light.c | 8 +++-- .../esp_zigbee_gpc/main/esp_zigbee_gpc.c | 12 +++++--- .../esp_zigbee_gpd/main/esp_zigbee_gpd.c | 10 +++++-- examples/esp_zigbee_host/main/esp_zb_host.c | 10 +++++-- .../ota_client/main/esp_ota_client.c | 10 +++++-- .../ota_server/main/esp_ota_server.c | 10 +++++-- .../main/esp_zb_sleepy_end_device.c | 29 ++++++++++--------- .../main/esp_touchlink_light.c | 8 +++-- .../main/esp_touchlink_switch.c | 10 +++++-- 16 files changed, 122 insertions(+), 57 deletions(-) diff --git a/examples/esp_zigbee_HA_sample/HA_color_dimmable_light/main/esp_zb_light.c b/examples/esp_zigbee_HA_sample/HA_color_dimmable_light/main/esp_zb_light.c index 6c98d76..c6a306f 100644 --- a/examples/esp_zigbee_HA_sample/HA_color_dimmable_light/main/esp_zb_light.c +++ b/examples/esp_zigbee_HA_sample/HA_color_dimmable_light/main/esp_zb_light.c @@ -28,8 +28,12 @@ static const char *TAG = "ESP_ZB_COLOR_DIMM_LIGHT"; /********************* Define functions **************************/ static esp_err_t deferred_driver_init(void) { - light_driver_init(LIGHT_DEFAULT_OFF); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + light_driver_init(LIGHT_DEFAULT_OFF); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) diff --git a/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c b/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c index 4a4e287..49159f3 100644 --- a/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c +++ b/examples/esp_zigbee_HA_sample/HA_color_dimmable_switch/main/esp_zb_switch.c @@ -83,9 +83,13 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) diff --git a/examples/esp_zigbee_HA_sample/HA_on_off_light/main/esp_zb_light.c b/examples/esp_zigbee_HA_sample/HA_on_off_light/main/esp_zb_light.c index d6cad96..a402971 100644 --- a/examples/esp_zigbee_HA_sample/HA_on_off_light/main/esp_zb_light.c +++ b/examples/esp_zigbee_HA_sample/HA_on_off_light/main/esp_zb_light.c @@ -27,8 +27,12 @@ static const char *TAG = "ESP_ZB_ON_OFF_LIGHT"; /********************* Define functions **************************/ static esp_err_t deferred_driver_init(void) { - light_driver_init(LIGHT_DEFAULT_OFF); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + light_driver_init(LIGHT_DEFAULT_OFF); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) diff --git a/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c b/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c index d4a7204..b3d61ab 100644 --- a/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c +++ b/examples/esp_zigbee_HA_sample/HA_on_off_switch/main/esp_zb_switch.c @@ -54,9 +54,13 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) diff --git a/examples/esp_zigbee_HA_sample/HA_temperature_sensor/main/esp_zb_temperature_sensor.c b/examples/esp_zigbee_HA_sample/HA_temperature_sensor/main/esp_zb_temperature_sensor.c index d27d786..6c97e3c 100644 --- a/examples/esp_zigbee_HA_sample/HA_temperature_sensor/main/esp_zb_temperature_sensor.c +++ b/examples/esp_zigbee_HA_sample/HA_temperature_sensor/main/esp_zb_temperature_sensor.c @@ -74,13 +74,18 @@ static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) static esp_err_t deferred_driver_init(void) { + static bool is_inited = false; temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(ESP_TEMP_SENSOR_MIN_VALUE, ESP_TEMP_SENSOR_MAX_VALUE); - ESP_RETURN_ON_ERROR(temp_sensor_driver_init(&temp_sensor_config, ESP_TEMP_SENSOR_UPDATE_INTERVAL, esp_app_temp_sensor_handler), TAG, - "Failed to initialize temperature sensor"); - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), esp_app_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + if (!is_inited) { + ESP_RETURN_ON_ERROR( + temp_sensor_driver_init(&temp_sensor_config, ESP_TEMP_SENSOR_UPDATE_INTERVAL, esp_app_temp_sensor_handler), + TAG, "Failed to initialize temperature sensor"); + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), esp_app_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) diff --git a/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c b/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c index c92b3e7..c50a169 100644 --- a/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c +++ b/examples/esp_zigbee_HA_sample/HA_thermostat/main/esp_zb_thermostat.c @@ -208,10 +208,15 @@ static void find_temperature_sensor(esp_zb_zdo_match_desc_req_param_t *param, es static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), esp_app_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), esp_app_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } + void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { uint32_t *p_sg_p = signal_struct->p_app_signal; diff --git a/examples/esp_zigbee_customized_devices/customized_client/main/esp_HA_customized_switch.c b/examples/esp_zigbee_customized_devices/customized_client/main/esp_HA_customized_switch.c index 2766d56..1555895 100644 --- a/examples/esp_zigbee_customized_devices/customized_client/main/esp_HA_customized_switch.c +++ b/examples/esp_zigbee_customized_devices/customized_client/main/esp_HA_customized_switch.c @@ -68,9 +68,13 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) diff --git a/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c b/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c index af546bd..72be190 100644 --- a/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c +++ b/examples/esp_zigbee_customized_devices/customized_server/main/esp_HA_customized_light.c @@ -24,8 +24,12 @@ static const char *TAG = "ESP_HA_ON_OFF_LIGHT"; static esp_err_t deferred_driver_init(void) { - light_driver_init(LIGHT_DEFAULT_OFF); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + light_driver_init(LIGHT_DEFAULT_OFF); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) diff --git a/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c b/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c index 743f05b..fde0922 100644 --- a/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c +++ b/examples/esp_zigbee_greenpower/esp_zigbee_gpc/main/esp_zigbee_gpc.c @@ -75,10 +75,14 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) static esp_err_t deferred_driver_init(void) { - light_driver_init(LIGHT_DEFAULT_OFF); - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + light_driver_init(LIGHT_DEFAULT_OFF); + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) diff --git a/examples/esp_zigbee_greenpower/esp_zigbee_gpd/main/esp_zigbee_gpd.c b/examples/esp_zigbee_greenpower/esp_zigbee_gpd/main/esp_zigbee_gpd.c index e7c68c0..92a0633 100644 --- a/examples/esp_zigbee_greenpower/esp_zigbee_gpd/main/esp_zigbee_gpd.c +++ b/examples/esp_zigbee_greenpower/esp_zigbee_gpd/main/esp_zigbee_gpd.c @@ -62,9 +62,13 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void zb_zgpd_signal_handler(esp_zb_zgpd_signal_t signal, esp_err_t error) diff --git a/examples/esp_zigbee_host/main/esp_zb_host.c b/examples/esp_zigbee_host/main/esp_zb_host.c index edeb585..bdb86c3 100644 --- a/examples/esp_zigbee_host/main/esp_zb_host.c +++ b/examples/esp_zigbee_host/main/esp_zb_host.c @@ -48,9 +48,13 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) diff --git a/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c b/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c index 5270ff0..9597203 100644 --- a/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c +++ b/examples/esp_zigbee_ota/ota_client/main/esp_ota_client.c @@ -65,9 +65,13 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask) diff --git a/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c b/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c index f49c863..2cdea91 100644 --- a/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c +++ b/examples/esp_zigbee_ota/ota_server/main/esp_ota_server.c @@ -68,9 +68,13 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) diff --git a/examples/esp_zigbee_sleep/light_sleep/main/esp_zb_sleepy_end_device.c b/examples/esp_zigbee_sleep/light_sleep/main/esp_zb_sleepy_end_device.c index ca6b545..3cb003f 100644 --- a/examples/esp_zigbee_sleep/light_sleep/main/esp_zb_sleepy_end_device.c +++ b/examples/esp_zigbee_sleep/light_sleep/main/esp_zb_sleepy_end_device.c @@ -68,23 +68,26 @@ static void zb_buttons_handler(switch_func_pair_t* button_func_pair) static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - /* Configure RTC IO wake up: - The configuration mode depends on your hardware design. - Since the BOOT button is connected to a pull-up resistor, the wake-up mode is configured as LOW. - */ - ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup( - 1ULL << CONFIG_GPIO_INPUT_IO_WAKEUP, ESP_EXT1_WAKEUP_ANY_LOW)); + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + /* Configure RTC IO wake up: + The configuration mode depends on your hardware design. + Since the BOOT button is connected to a pull-up resistor, the wake-up mode is configured as LOW. + */ + ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(1ULL << CONFIG_GPIO_INPUT_IO_WAKEUP, ESP_EXT1_WAKEUP_ANY_LOW)); #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED - rtc_gpio_pulldown_dis(CONFIG_GPIO_INPUT_IO_WAKEUP); - rtc_gpio_pullup_en(CONFIG_GPIO_INPUT_IO_WAKEUP); + rtc_gpio_pulldown_dis(CONFIG_GPIO_INPUT_IO_WAKEUP); + rtc_gpio_pullup_en(CONFIG_GPIO_INPUT_IO_WAKEUP); #else - gpio_pulldown_dis(CONFIG_GPIO_INPUT_IO_WAKEUP); - gpio_pullup_en(CONFIG_GPIO_INPUT_IO_WAKEUP); + gpio_pulldown_dis(CONFIG_GPIO_INPUT_IO_WAKEUP); + gpio_pullup_en(CONFIG_GPIO_INPUT_IO_WAKEUP); #endif - return ESP_OK; + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } /********************* Define functions **************************/ diff --git a/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c b/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c index 0b7e615..c044c23 100644 --- a/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c +++ b/examples/esp_zigbee_touchlink/touchlink_light/main/esp_touchlink_light.c @@ -29,8 +29,12 @@ static const char *TAG = "ESP_TL_ON_OFF_LIGHT"; static esp_err_t deferred_driver_init(void) { - light_driver_init(LIGHT_DEFAULT_OFF); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + light_driver_init(LIGHT_DEFAULT_OFF); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) diff --git a/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c b/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c index 499c899..8486072 100644 --- a/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c +++ b/examples/esp_zigbee_touchlink/touchlink_switch/main/esp_touchlink_switch.c @@ -78,9 +78,13 @@ static void zb_buttons_handler(switch_func_pair_t *button_func_pair) static esp_err_t deferred_driver_init(void) { - ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), ESP_FAIL, TAG, - "Failed to initialize switch driver"); - return ESP_OK; + static bool is_inited = false; + if (!is_inited) { + ESP_RETURN_ON_FALSE(switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), zb_buttons_handler), + ESP_FAIL, TAG, "Failed to initialize switch driver"); + is_inited = true; + } + return is_inited ? ESP_OK : ESP_FAIL; } static void bind_cb(esp_zb_zdp_status_t zdo_status, void *user_ctx)