diff --git a/components/esp_matter/esp_matter_client.cpp b/components/esp_matter/esp_matter_client.cpp index 182425c7e..e1daba085 100644 --- a/components/esp_matter/esp_matter_client.cpp +++ b/components/esp_matter/esp_matter_client.cpp @@ -170,6 +170,7 @@ void binding_manager_init() { if (initialize_binding_manager) { chip::DeviceLayer::PlatformMgr().ScheduleWork(__binding_manager_init); + initialize_binding_manager = false; } } diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index ca4b056eb..c790ed97a 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -788,15 +788,11 @@ static void esp_matter_chip_init_task(intptr_t context) sWiFiNetworkCommissioningInstance.Init(); } #endif - /* Initialize binding manager */ - client::binding_manager_init(); xTaskNotifyGive(task_to_notify); } static void device_callback_internal(const ChipDeviceEvent * event, intptr_t arg) { - // TODO: Use RemoveEventHandler() instead of the static is_ota_requestor_start - static bool is_ota_requestor_start = false; switch (event->Type) { case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: @@ -812,19 +808,18 @@ static void device_callback_internal(const ChipDeviceEvent * event, intptr_t arg // in esp_matter_ota_requestor_start(), so the device should be connected to the Wi-Fi network when calling // esp_matter_ota_requestor_start(). IPv4 might be disabled on the Provider so we should call this function // when the IPv6 address is assigned. - if (!is_ota_requestor_start) { - esp_matter_ota_requestor_start(); - is_ota_requestor_start = true; - } + esp_matter_ota_requestor_start(); + /* Initialize binding manager */ + client::binding_manager_init(); } break; #if CHIP_DEVICE_CONFIG_ENABLE_THREAD case chip::DeviceLayer::DeviceEventType::kThreadConnectivityChange: - if (!is_ota_requestor_start && - event->ThreadConnectivityChange.Result == chip::DeviceLayer::ConnectivityChange::kConnectivity_Established) { + if (event->ThreadConnectivityChange.Result == chip::DeviceLayer::ConnectivityChange::kConnectivity_Established) { esp_matter_ota_requestor_start(); - is_ota_requestor_start = true; + /* Initialize binding manager */ + client::binding_manager_init(); } break; #endif diff --git a/components/esp_matter/esp_matter_ota.cpp b/components/esp_matter/esp_matter_ota.cpp index 2598a1c3e..ecef01c70 100644 --- a/components/esp_matter/esp_matter_ota.cpp +++ b/components/esp_matter/esp_matter_ota.cpp @@ -26,15 +26,15 @@ using chip::BDXDownloader; using chip::DefaultOTARequestor; using chip::DefaultOTARequestorStorage; -using chip::DeviceLayer::DefaultOTARequestorDriver; using chip::OTAImageProcessorImpl; using chip::Server; +using chip::DeviceLayer::DefaultOTARequestorDriver; using namespace esp_matter; using namespace esp_matter::endpoint; using namespace esp_matter::cluster; -#if CONFIG_ENABLE_OTA_REQUESTOR +#if CONFIG_ENABLE_OTA_REQUESTOR DefaultOTARequestor gRequestorCore; DefaultOTARequestorStorage gRequestorStorage; DefaultOTARequestorDriver gRequestorUser; @@ -52,7 +52,7 @@ esp_err_t esp_matter_ota_requestor_init(void) if (!root_node || !root_node_endpoint) { return ESP_FAIL; } - + cluster_t *cluster_p = ota_provider::create(root_node_endpoint, NULL, CLUSTER_FLAG_CLIENT); cluster_t *cluster_r = ota_requestor::create(root_node_endpoint, &config, CLUSTER_FLAG_SERVER); @@ -68,7 +68,8 @@ esp_err_t esp_matter_ota_requestor_init(void) void esp_matter_ota_requestor_start(void) { -#if CONFIG_ENABLE_OTA_REQUESTOR +#if CONFIG_ENABLE_OTA_REQUESTOR + VerifyOrReturn(chip::GetRequestorInstance() == nullptr); chip::SetRequestorInstance(&gRequestorCore); gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage()); gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);