diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt index decf90b2a8cbc7..ecb117a47dd600 100644 --- a/.github/.wordlist.txt +++ b/.github/.wordlist.txt @@ -726,6 +726,7 @@ OTA OTADownloader OTAImageProcessorDriver OTAImageProcessorInterface +OTAProvider OTAProviderIpAddress OTAProviderNodeId OTAProviderSerialPort diff --git a/examples/lighting-app/esp32/README.md b/examples/lighting-app/esp32/README.md index 534e6ec3df0c16..51ca945b63140d 100644 --- a/examples/lighting-app/esp32/README.md +++ b/examples/lighting-app/esp32/README.md @@ -142,10 +142,10 @@ scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/debug c hello-world.bin can be obtained from compiling the hello-world ESP-IDF example. -- Provision the Linux OTA Provider using chip-tool +- Commission the Linux OTA Provider using chip-tool ``` -./out/debug/chip-tool pairing onnetwork 12345 20202021 +./out/debug/chip-tool pairing onnetwork 12346 20202021 ``` ## Query for an OTA Image @@ -154,10 +154,11 @@ After commissioning is successful, press Enter in requestor device console and type below query. ``` ->matter ota query 1 12345 0 +>matter ota query 1 12346 0 ``` ## Apply update -Once transfer is complete, reboot the device manually to boot from upgraded OTA -image. +Once the transfer is complete, OTA requestor sends ApplyUpdateRequest command to +OTA provider for applying the image. Device will restart on successful +application of OTA image. diff --git a/examples/lighting-app/esp32/main/main.cpp b/examples/lighting-app/esp32/main/main.cpp index b26a2fa6afd2e6..c3114e04c2b363 100644 --- a/examples/lighting-app/esp32/main/main.cpp +++ b/examples/lighting-app/esp32/main/main.cpp @@ -57,12 +57,10 @@ static void InitOTARequestor(void) { #if CONFIG_ENABLE_OTA_REQUESTOR SetRequestorInstance(&gRequestorCore); - gRequestorCore.SetServerInstance(&Server::GetInstance()); - gRequestorCore.SetOtaRequestorDriver(&gRequestorUser); + gRequestorCore.Init(&Server::GetInstance(), &gRequestorUser, &gDownloader); gImageProcessor.SetOTADownloader(&gDownloader); gDownloader.SetImageProcessorDelegate(&gImageProcessor); gRequestorUser.Init(&gRequestorCore, &gImageProcessor); - gRequestorCore.SetBDXDownloader(&gDownloader); #endif } diff --git a/examples/ota-provider-app/esp32/README.md b/examples/ota-provider-app/esp32/README.md index c849db6afd95d6..af830a81c95c45 100644 --- a/examples/ota-provider-app/esp32/README.md +++ b/examples/ota-provider-app/esp32/README.md @@ -41,6 +41,15 @@ idf.py -p flash ./out/debug/chip-tool pairing ble-wifi 12345 20202021 3841 ``` +## Set delayed action time (Optional) + +- Set delayed action time in the Query Image Response and Apply Update + Response, default is zero. + +``` +> matter OTAProvider delay +``` + --- Once OTA provider is commissioned then head over to diff --git a/examples/ota-provider-app/esp32/main/CMakeLists.txt b/examples/ota-provider-app/esp32/main/CMakeLists.txt index 2d673860ea9668..bba24522ae33ad 100644 --- a/examples/ota-provider-app/esp32/main/CMakeLists.txt +++ b/examples/ota-provider-app/esp32/main/CMakeLists.txt @@ -48,6 +48,7 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-provider" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/ota-provider-app/ota-provider-common" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension" EXCLUDE_SRCS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/ota-provider-app/ota-provider-common/BdxOtaSender.cpp" PRIV_REQUIRES chip QRCode bt console spiffs) diff --git a/examples/ota-provider-app/esp32/main/OTAProviderCommands.cpp b/examples/ota-provider-app/esp32/main/OTAProviderCommands.cpp new file mode 100644 index 00000000000000..58bf1ee1320f16 --- /dev/null +++ b/examples/ota-provider-app/esp32/main/OTAProviderCommands.cpp @@ -0,0 +1,87 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace chip { +namespace Shell { +namespace { + +OTAProviderExample * exampleOTAProvider = nullptr; +Shell::Engine sSubShell; + +CHIP_ERROR DelayedActionTimeHandler(int argc, char ** argv) +{ + VerifyOrReturnError(argc == 1, CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(exampleOTAProvider != nullptr, CHIP_ERROR_INCORRECT_STATE); + + const uint32_t delay = strtoul(argv[0], nullptr, 10); + exampleOTAProvider->SetDelayedActionTimeSec(delay); + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAProviderHandler(int argc, char ** argv) +{ + if (argc == 0) + { + sSubShell.ForEachCommand(PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; + } + + CHIP_ERROR error = sSubShell.ExecCommand(argc, argv); + + if (error != CHIP_NO_ERROR) + { + streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", error.Format()); + } + + return error; +} +} // namespace + +void OTAProviderCommands::Register() +{ + // These commands can be moved to src/lib/shell/commands/Ota.cpp along with the other OTA commands. + // But as of now only Linux and ESP32 platforms supports OTA provider + + // Register subcommands of the `OTAProvider` commands. + static const shell_command_t subCommands[] = { + { &DelayedActionTimeHandler, "delay", + "Set delayed action time for QueryImageResponse and ApplyUpdateResponse\n" + "Usage: OTAProvider delay " }, + }; + + sSubShell.RegisterCommands(subCommands, ArraySize(subCommands)); + + // Register the root `OTA Provider` command in the top-level shell. + static const shell_command_t otaProviderCommand = { &OTAProviderHandler, "OTAProvider", "OTA Provider commands" }; + + Engine::Root().RegisterCommands(&otaProviderCommand, 1); +} + +// Set Example OTA provider +void OTAProviderCommands::SetExampleOTAProvider(OTAProviderExample * otaProvider) +{ + exampleOTAProvider = otaProvider; +} + +} // namespace Shell +} // namespace chip diff --git a/examples/ota-provider-app/esp32/main/include/OTAProviderCommands.h b/examples/ota-provider-app/esp32/main/include/OTAProviderCommands.h new file mode 100644 index 00000000000000..25eaa0cea6262e --- /dev/null +++ b/examples/ota-provider-app/esp32/main/include/OTAProviderCommands.h @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +namespace chip { +namespace Shell { + +class OTAProviderCommands +{ +public: + // delete the copy constructor + OTAProviderCommands(const OTAProviderCommands &) = delete; + // delete the move constructor + OTAProviderCommands(OTAProviderCommands &&) = delete; + // delete the assignment operator + OTAProviderCommands & operator=(const OTAProviderCommands &) = delete; + + static OTAProviderCommands & GetInstance() + { + static OTAProviderCommands instance; + return instance; + } + + // Register the OTA provider commands + void Register(); + + // Set Example OTA provider + void SetExampleOTAProvider(OTAProviderExample * otaProvider); + +private: + OTAProviderCommands() {} +}; + +} // namespace Shell +} // namespace chip diff --git a/examples/ota-provider-app/esp32/main/main.cpp b/examples/ota-provider-app/esp32/main/main.cpp index bd64837a3eb710..7c5ea0aa337e93 100644 --- a/examples/ota-provider-app/esp32/main/main.cpp +++ b/examples/ota-provider-app/esp32/main/main.cpp @@ -17,36 +17,25 @@ #include "CHIPDeviceManager.h" #include "DeviceCallbacks.h" -#include "esp_heap_caps_init.h" #include "esp_log.h" -#include "esp_netif.h" #include "esp_spi_flash.h" #include "esp_spiffs.h" -#include "esp_system.h" -#include "esp_wifi.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" #include "nvs_flash.h" -#include #include -#include - -#include -#include -#include -#include - #include #include - #include +#include +#include #include #include #include +#include using chip::Callback::Callback; using namespace ::chip; +using namespace ::chip::Shell; using namespace ::chip::System; using namespace ::chip::Credentials; using namespace ::chip::DeviceManager; @@ -130,17 +119,6 @@ extern "C" void app_main() { ESP_LOGI(TAG, "OTA Provider!"); - /* Print chip information */ - esp_chip_info_t chip_info; - esp_chip_info(&chip_info); - ESP_LOGI(TAG, "This is ESP32 chip with %d CPU cores, WiFi%s%s, ", chip_info.cores, - (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : ""); - - ESP_LOGI(TAG, "silicon revision %d, ", chip_info.revision); - - ESP_LOGI(TAG, "%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024), - (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external"); - // Initialize the ESP NVS layer. esp_err_t err = nvs_flash_init(); if (err != ESP_OK) @@ -216,4 +194,10 @@ extern "C" void app_main() } chip::app::Clusters::OTAProvider::SetDelegate(kOtaProviderEndpoint, &otaProvider); + + // Launch a chip shell and register OTA Provider Commands + chip::LaunchShell(); + OTAProviderCommands & otaProviderCommands = OTAProviderCommands::GetInstance(); + otaProviderCommands.SetExampleOTAProvider(&otaProvider); + otaProviderCommands.Register(); } diff --git a/examples/ota-provider-app/esp32/sdkconfig.defaults b/examples/ota-provider-app/esp32/sdkconfig.defaults index aaae13fbb5c092..89258be810acd8 100644 --- a/examples/ota-provider-app/esp32/sdkconfig.defaults +++ b/examples/ota-provider-app/esp32/sdkconfig.defaults @@ -55,3 +55,6 @@ CONFIG_ESPTOOLPY_FLASHSIZE="4MB" # discriminator CONFIG_USE_TEST_SETUP_DISCRIMINATOR=0xF01 + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y diff --git a/examples/ota-provider-app/linux/main.cpp b/examples/ota-provider-app/linux/main.cpp index 9242ab780e41ce..733d40f35b1283 100644 --- a/examples/ota-provider-app/linux/main.cpp +++ b/examples/ota-provider-app/linux/main.cpp @@ -124,7 +124,8 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" " -q/--QueryImageBehavior \n" " Status value in the Query Image Response\n" " -d/--DelayedActionTimeSec