diff --git a/components/esp_matter/CMakeLists.txt b/components/esp_matter/CMakeLists.txt index f7da41d6c..e3f4fcbee 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) +set(REQUIRES_LIST chip bt esp_matter_console nvs_flash app_update esp32_mbedtls esp_system) 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 3213d4db9..3fee603b9 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -32,6 +32,7 @@ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include #endif +#include using chip::CommandId; using chip::DataVersion; @@ -740,10 +741,17 @@ static esp_err_t chip_init(event_callback_t callback) esp_err_t start(event_callback_t callback) { + esp_err_t ota_err = esp_matter_ota_requestor_init(); + esp_err_t err = chip_init(callback); if (err != ESP_OK) { ESP_LOGE(TAG, "Error initializing matter"); } + + if ((ota_err == ESP_OK) && (err == ESP_OK)) { + esp_matter_ota_requestor_start(); + } + return err; } diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index ee03b2c3b..53c140f7f 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -65,8 +65,6 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat descriptor::create(endpoint, CLUSTER_FLAG_SERVER); access_control::create(endpoint, CLUSTER_FLAG_SERVER); basic::create(endpoint, &(config->basic), CLUSTER_FLAG_SERVER); - ota_provider::create(endpoint, NULL, CLUSTER_FLAG_CLIENT); - ota_requestor::create(endpoint, &(config->ota_requestor), CLUSTER_FLAG_SERVER); general_commissioning::create(endpoint, &(config->general_commissioning), CLUSTER_FLAG_SERVER); network_commissioning::create(endpoint, &(config->network_commissioning), CLUSTER_FLAG_SERVER); general_diagnostics::create(endpoint, &(config->general_diagnostics), CLUSTER_FLAG_SERVER); diff --git a/components/esp_matter/esp_matter_endpoint.h b/components/esp_matter/esp_matter_endpoint.h index 76ef72490..520b11adf 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -33,7 +33,6 @@ namespace endpoint { namespace root_node { typedef struct config { cluster::basic::config_t basic; - cluster::ota_requestor::config_t ota_requestor; cluster::general_commissioning::config_t general_commissioning; cluster::network_commissioning::config_t network_commissioning; cluster::general_diagnostics::config_t general_diagnostics; diff --git a/components/esp_matter_ota/esp_matter_ota.cpp b/components/esp_matter/esp_matter_ota.cpp similarity index 66% rename from components/esp_matter_ota/esp_matter_ota.cpp rename to components/esp_matter/esp_matter_ota.cpp index 3d4b70ac2..2598a1c3e 100644 --- a/components/esp_matter_ota/esp_matter_ota.cpp +++ b/components/esp_matter/esp_matter_ota.cpp @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include #include @@ -22,26 +21,59 @@ #include #include +#include + using chip::BDXDownloader; using chip::DefaultOTARequestor; using chip::DefaultOTARequestorStorage; using chip::DeviceLayer::DefaultOTARequestorDriver; using chip::OTAImageProcessorImpl; using chip::Server; + +using namespace esp_matter; +using namespace esp_matter::endpoint; +using namespace esp_matter::cluster; + #if CONFIG_ENABLE_OTA_REQUESTOR DefaultOTARequestor gRequestorCore; DefaultOTARequestorStorage gRequestorStorage; DefaultOTARequestorDriver gRequestorUser; BDXDownloader gDownloader; OTAImageProcessorImpl gImageProcessor; +#endif -void esp_matter_ota_requestor_init(void) +esp_err_t esp_matter_ota_requestor_init(void) { +#if (CONFIG_ENABLE_OTA_REQUESTOR && (FIXED_ENDPOINT_COUNT == 0)) + ota_requestor::config_t config; + node_t *root_node = esp_matter::node::get(); + endpoint_t *root_node_endpoint = esp_matter::endpoint::get(root_node, 0); + + 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); + + if (!cluster_p || !cluster_r) { + return ESP_FAIL; + } + + return ESP_OK; +#else + return ESP_ERR_NOT_SUPPORTED; +#endif +} + +void esp_matter_ota_requestor_start(void) +{ +#if CONFIG_ENABLE_OTA_REQUESTOR chip::SetRequestorInstance(&gRequestorCore); gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage()); gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); gImageProcessor.SetOTADownloader(&gDownloader); gDownloader.SetImageProcessorDelegate(&gImageProcessor); gRequestorUser.Init(&gRequestorCore, &gImageProcessor); -} #endif +} diff --git a/components/esp_matter_ota/esp_matter_ota.h b/components/esp_matter/esp_matter_ota.h similarity index 79% rename from components/esp_matter_ota/esp_matter_ota.h rename to components/esp_matter/esp_matter_ota.h index b01aebed4..945dbb219 100644 --- a/components/esp_matter_ota/esp_matter_ota.h +++ b/components/esp_matter/esp_matter_ota.h @@ -17,9 +17,12 @@ #include "esp_err.h" #include "sdkconfig.h" -#if CONFIG_ENABLE_OTA_REQUESTOR -/** Initialize the matter OTA Requestor +/** Initialize the Matter OTA Requestor * */ -void esp_matter_ota_requestor_init(void); -#endif +esp_err_t esp_matter_ota_requestor_init(void); + +/**Start the Matter OTA Requestor + * + */ +void esp_matter_ota_requestor_start(void); diff --git a/components/esp_matter_ota/CMakeLists.txt b/components/esp_matter_ota/CMakeLists.txt deleted file mode 100644 index ea7b5dabc..000000000 --- a/components/esp_matter_ota/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -idf_component_register(SRCS "esp_matter_ota.cpp" - INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}" - REQUIRES esp_matter app_update esp32_mbedtls esp_system) diff --git a/examples/blemesh_bridge/main/CMakeLists.txt b/examples/blemesh_bridge/main/CMakeLists.txt index f2de25c7d..e99dc3c5c 100644 --- a/examples/blemesh_bridge/main/CMakeLists.txt +++ b/examples/blemesh_bridge/main/CMakeLists.txt @@ -1,4 +1,4 @@ -set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode esp_matter_ota app_bridge) +set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_bridge) idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." diff --git a/examples/blemesh_bridge/main/app_main.cpp b/examples/blemesh_bridge/main/app_main.cpp index f9774710b..761dc1769 100644 --- a/examples/blemesh_bridge/main/app_main.cpp +++ b/examples/blemesh_bridge/main/app_main.cpp @@ -84,8 +84,4 @@ extern "C" void app_main() esp_matter_console_diagnostics_register_commands(); esp_matter_console_init(); #endif - -#if CONFIG_ENABLE_OTA_REQUESTOR - esp_matter_ota_requestor_init(); -#endif } diff --git a/examples/light/main/CMakeLists.txt b/examples/light/main/CMakeLists.txt index b9a2c8e4b..3ac9120af 100644 --- a/examples/light/main/CMakeLists.txt +++ b/examples/light/main/CMakeLists.txt @@ -1,4 +1,4 @@ -set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota) +set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset) idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." diff --git a/examples/light/main/app_main.cpp b/examples/light/main/app_main.cpp index 0451c3d8e..2aad2f2c6 100644 --- a/examples/light/main/app_main.cpp +++ b/examples/light/main/app_main.cpp @@ -114,8 +114,4 @@ extern "C" void app_main() esp_matter_console_diagnostics_register_commands(); esp_matter_console_init(); #endif - -#if CONFIG_ENABLE_OTA_REQUESTOR - esp_matter_ota_requestor_init(); -#endif } diff --git a/examples/light_switch/main/CMakeLists.txt b/examples/light_switch/main/CMakeLists.txt index b9a2c8e4b..3ac9120af 100644 --- a/examples/light_switch/main/CMakeLists.txt +++ b/examples/light_switch/main/CMakeLists.txt @@ -1,4 +1,4 @@ -set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota) +set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset) idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." diff --git a/examples/light_switch/main/app_main.cpp b/examples/light_switch/main/app_main.cpp index 2d57e5956..5cf501a84 100644 --- a/examples/light_switch/main/app_main.cpp +++ b/examples/light_switch/main/app_main.cpp @@ -103,8 +103,4 @@ extern "C" void app_main() esp_matter_console_diagnostics_register_commands(); esp_matter_console_init(); #endif - -#if CONFIG_ENABLE_OTA_REQUESTOR - esp_matter_ota_requestor_init(); -#endif } diff --git a/examples/zigbee_bridge/main/CMakeLists.txt b/examples/zigbee_bridge/main/CMakeLists.txt index b9158b4ee..e99c48f4a 100644 --- a/examples/zigbee_bridge/main/CMakeLists.txt +++ b/examples/zigbee_bridge/main/CMakeLists.txt @@ -1,4 +1,4 @@ -set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode esp_matter_ota app_bridge +set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_bridge esp-zboss-lib) idf_component_register(SRC_DIRS "." diff --git a/examples/zigbee_bridge/main/app_main.cpp b/examples/zigbee_bridge/main/app_main.cpp index 770fe50aa..cd540103a 100644 --- a/examples/zigbee_bridge/main/app_main.cpp +++ b/examples/zigbee_bridge/main/app_main.cpp @@ -83,9 +83,5 @@ extern "C" void app_main() esp_matter_console_diagnostics_register_commands(); esp_matter_console_init(); #endif - -#if CONFIG_ENABLE_OTA_REQUESTOR - esp_matter_ota_requestor_init(); -#endif launch_app_zboss(); }