diff --git a/examples/all-clusters-app/esp32/main/main.cpp b/examples/all-clusters-app/esp32/main/main.cpp index 1410ac504ddb22..83311f6ac2d0b0 100644 --- a/examples/all-clusters-app/esp32/main/main.cpp +++ b/examples/all-clusters-app/esp32/main/main.cpp @@ -70,7 +70,8 @@ using namespace ::chip::DeviceLayer; // Used to indicate that an IP address has been added to the QRCode #define EXAMPLE_VENDOR_TAG_IP 1 -const char * TAG = "all-clusters-app"; +const char * TAG = "all-clusters-app"; +const uint32_t delayNotifySeconds = 10; static DeviceCallbacks EchoCallbacks; @@ -114,6 +115,7 @@ static void InitOTARequestor(void) gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); gImageProcessor.SetOTADownloader(&gDownloader); gDownloader.SetImageProcessorDelegate(&gImageProcessor); + gRequestorUser.DelayNotifyUpdateAppliedAction(delayNotifySeconds); gRequestorUser.Init(&gRequestorCore, &gImageProcessor); #endif } diff --git a/examples/lighting-app/esp32/main/main.cpp b/examples/lighting-app/esp32/main/main.cpp index 5a0b4c12c9db9c..c0b3feeae07459 100644 --- a/examples/lighting-app/esp32/main/main.cpp +++ b/examples/lighting-app/esp32/main/main.cpp @@ -58,7 +58,8 @@ OTAImageProcessorImpl gImageProcessor; LEDWidget AppLED; -static const char * TAG = "light-app"; +static const char * TAG = "light-app"; +const uint32_t delayNotifySeconds = 10; static DeviceCallbacks EchoCallbacks; namespace { @@ -80,6 +81,7 @@ static void InitOTARequestor(void) gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); gImageProcessor.SetOTADownloader(&gDownloader); gDownloader.SetImageProcessorDelegate(&gImageProcessor); + gRequestorUser.DelayNotifyUpdateAppliedAction(delayNotifySeconds); gRequestorUser.Init(&gRequestorCore, &gImageProcessor); #endif } diff --git a/examples/ota-requestor-app/esp32/main/main.cpp b/examples/ota-requestor-app/esp32/main/main.cpp index 5f962d712d8db1..18e22851aa78f2 100644 --- a/examples/ota-requestor-app/esp32/main/main.cpp +++ b/examples/ota-requestor-app/esp32/main/main.cpp @@ -50,7 +50,8 @@ using namespace ::chip::DeviceManager; using namespace ::chip::DeviceLayer; namespace { -const char * TAG = "ota-requester-app"; +const char * TAG = "ota-requester-app"; +const uint32_t delayNotifySeconds = 10; static DeviceCallbacks EchoCallbacks; DefaultOTARequestor gRequestorCore; @@ -78,6 +79,7 @@ static void InitServer(intptr_t context) gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); gImageProcessor.SetOTADownloader(&gDownloader); gDownloader.SetImageProcessorDelegate(&gImageProcessor); + gRequestorUser.DelayNotifyUpdateAppliedAction(delayNotifySeconds); gRequestorUser.Init(&gRequestorCore, &gImageProcessor); } diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp index 4b56e57b506021..fa33d09a30d0f1 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp @@ -48,7 +48,8 @@ using namespace app::Clusters::OtaSoftwareUpdateRequestor::Structs; constexpr uint32_t kDelayQueryUponCommissioningSec = 30; // Delay before sending the initial image query after commissioning constexpr uint32_t kImmediateStartDelaySec = 1; // Delay before sending a query in response to UrgentUpdateAvailable constexpr System::Clock::Seconds32 kDefaultDelayedActionTime = System::Clock::Seconds32(120); -constexpr uint32_t kDelayNotifyUpdateApplied = 10; // Delay before sending notify update applied command +System::Clock::Seconds32 mDelayNotifyUpdateAppliedSeconds = + System::Clock::Seconds32(0); // Delay before sending notify update applied command DefaultOTARequestorDriver * ToDriver(void * context) { @@ -57,13 +58,9 @@ DefaultOTARequestorDriver * ToDriver(void * context) } // namespace -void ScheduleNotifyUpdateApplied(chip::System::Layer * systemLayer, void * appState) +void GenericOTARequestorDriver::DelayNotifyUpdateAppliedAction(uint32_t seconds) { - OTARequestorInterface * requestor = static_cast(appState); - if (requestor != nullptr) - { - requestor->NotifyUpdateApplied(); - } + mDelayNotifyUpdateAppliedSeconds = System::Clock::Seconds32(seconds); } void GenericOTARequestorDriver::Init(OTARequestorInterface * requestor, OTAImageProcessorInterface * processor) @@ -74,19 +71,20 @@ void GenericOTARequestorDriver::Init(OTARequestorInterface * requestor, OTAImage if (mImageProcessor->IsFirstImageRun()) { - SystemLayer().ScheduleLambda([this] { - CHIP_ERROR error = mImageProcessor->ConfirmCurrentImage(); - - if (error != CHIP_NO_ERROR) - { - ChipLogError(SoftwareUpdate, "Failed to confirm image: %" CHIP_ERROR_FORMAT, error.Format()); - mRequestor->Reset(); - return; - } - - chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kDelayNotifyUpdateApplied), - ScheduleNotifyUpdateApplied, mRequestor); - }); + ScheduleDelayedAction( + mDelayNotifyUpdateAppliedSeconds, + [](System::Layer *, void * context) { + CHIP_ERROR error = ToDriver(context)->mImageProcessor->ConfirmCurrentImage(); + if (error != CHIP_NO_ERROR) + { + ChipLogError(SoftwareUpdate, "Failed to confirm image: %" CHIP_ERROR_FORMAT, error.Format()); + ToDriver(context)->mRequestor->Reset(); + return; + } + + ToDriver(context)->mRequestor->NotifyUpdateApplied(); + }, + this); } else if ((mRequestor->GetCurrentUpdateState() != OTAUpdateStateEnum::kIdle)) { diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h index 24df0922156433..d6c6038ef4205d 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h @@ -80,6 +80,7 @@ class DefaultOTARequestorDriver : public OTARequestorDriver app::Clusters::OtaSoftwareUpdateRequestor::OTAAnnouncementReason announcementReason) override; void SendQueryImage() override; bool GetNextProviderLocation(ProviderLocationType & providerLocation, bool & listExhausted) override; + void DelayNotifyUpdateAppliedAction(uint32_t seconds); protected: void StartPeriodicQueryTimer();