diff --git a/components/esp_matter/CMakeLists.txt b/components/esp_matter/CMakeLists.txt index e3f4fcbee..503a4ac8c 100644 --- a/components/esp_matter/CMakeLists.txt +++ b/components/esp_matter/CMakeLists.txt @@ -71,7 +71,7 @@ set(INCLUDE_DIRS_LIST "." "${MATTER_SDK_PATH}/src" "${ZAP_GENERATED_PATH}/../") -set(REQUIRES_LIST chip bt esp_matter_console nvs_flash app_update esp32_mbedtls esp_system) +set(REQUIRES_LIST chip bt esp_matter_console nvs_flash app_update esp32_mbedtls esp_system route_hook) if ("${IDF_TARGET}" STREQUAL "esp32h2") list(APPEND REQUIRES_LIST openthread esp_matter_openthread) diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 639976305..62dfbce44 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -32,6 +32,7 @@ #include #endif #include +#include using chip::CommandId; using chip::DataVersion; @@ -714,13 +715,25 @@ static void esp_matter_chip_init_task(intptr_t context) xTaskNotifyGive(task_to_notify); } -static void device_callback_for_ota(const ChipDeviceEvent * event, intptr_t arg) +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: +#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD + if (event->InterfaceIpAddressChanged.Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV6_Assigned || + event->InterfaceIpAddressChanged.Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV4_Assigned) { + chip::app::DnssdServer::Instance().StartServer(); + esp_route_hook_init(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")); + } +#endif if (event->InterfaceIpAddressChanged.Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV6_Assigned) { + // When the OTA image is applied, the device will reboot and send the NotifyUpdateApplied to the Provider + // 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; @@ -758,7 +771,7 @@ static esp_err_t chip_init(event_callback_t callback) ESP_LOGE(TAG, "Failed to launch Matter main task"); return ESP_FAIL; } - PlatformMgr().AddEventHandler(device_callback_for_ota, static_cast(NULL)); + PlatformMgr().AddEventHandler(device_callback_internal, static_cast(NULL)); PlatformMgr().AddEventHandler(callback, static_cast(NULL)); #if CHIP_DEVICE_CONFIG_ENABLE_THREAD if (ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR) { @@ -801,7 +814,6 @@ esp_err_t start(event_callback_t callback) ESP_LOGE(TAG, "Error initializing matter"); } - return err; } diff --git a/examples/blemesh_bridge/main/app_main.cpp b/examples/blemesh_bridge/main/app_main.cpp index 8fbe97ef6..bd2f058cd 100644 --- a/examples/blemesh_bridge/main/app_main.cpp +++ b/examples/blemesh_bridge/main/app_main.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -30,10 +29,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { switch (event->Type) { case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: -#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD - chip::app::DnssdServer::Instance().StartServer(); - esp_route_hook_init(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")); -#endif + ESP_LOGI(TAG, "Interface IP Address Changed"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: diff --git a/examples/light/main/app_main.cpp b/examples/light/main/app_main.cpp index a5592f1d0..94fd5b01c 100644 --- a/examples/light/main/app_main.cpp +++ b/examples/light/main/app_main.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -31,10 +30,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { switch (event->Type) { case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: -#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD - chip::app::DnssdServer::Instance().StartServer(); - esp_route_hook_init(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")); -#endif + ESP_LOGI(TAG, "Interface IP Address changed"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: diff --git a/examples/light_switch/main/app_main.cpp b/examples/light_switch/main/app_main.cpp index 010c336ae..700366720 100644 --- a/examples/light_switch/main/app_main.cpp +++ b/examples/light_switch/main/app_main.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -30,10 +29,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { switch (event->Type) { case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: -#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD - chip::app::DnssdServer::Instance().StartServer(); - esp_route_hook_init(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")); -#endif + ESP_LOGI(TAG, "Interface IP Address Changed"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: diff --git a/examples/zap_light/main/app_main.cpp b/examples/zap_light/main/app_main.cpp index f16d63613..29072cbbb 100644 --- a/examples/zap_light/main/app_main.cpp +++ b/examples/zap_light/main/app_main.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -29,10 +28,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { switch (event->Type) { case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: -#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD - chip::app::DnssdServer::Instance().StartServer(); - esp_route_hook_init(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")); -#endif + ESP_LOGI(TAG, "Interface IP Address Changed"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: diff --git a/examples/zigbee_bridge/main/app_main.cpp b/examples/zigbee_bridge/main/app_main.cpp index bb40871dc..5b2c87233 100644 --- a/examples/zigbee_bridge/main/app_main.cpp +++ b/examples/zigbee_bridge/main/app_main.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -29,10 +28,7 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { switch (event->Type) { case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: -#if !CHIP_DEVICE_CONFIG_ENABLE_THREAD - chip::app::DnssdServer::Instance().StartServer(); - esp_route_hook_init(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")); -#endif + ESP_LOGI(TAG, "Interface IP Address Changed"); break; case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: