Skip to content

Commit

Permalink
[ESP32] Add menuconfig options for reboot on OTA image apply (#24379)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 authored Jan 16, 2023
1 parent d87f3d6 commit 9fbcf1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ menu "CHIP Core"
help
Enable this option to enable OTA Requestor for example

config OTA_AUTO_REBOOT_ON_APPLY
bool "Reboot the device after applying the OTA image"
depends on ENABLE_OTA_REQUESTOR
default y
help
Enable this option to reboot the device after applying the new image.

config OTA_AUTO_REBOOT_DELAY_MS
int "OTA reboot delay time (ms)"
depends on OTA_AUTO_REBOOT_ON_APPLY
default 5000
help
The delay time for OTA reboot on applying.

endmenu # "System Options"

menu "Security Options"
Expand Down
6 changes: 5 additions & 1 deletion src/platform/ESP32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,12 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)

PostOTAStateChangeEvent(DeviceLayer::kOtaApplyComplete);

#if CONFIG_OTA_AUTO_REBOOT_ON_APPLY
// HandleApply is called after delayed action time seconds are elapsed, so it would be safe to schedule the restart
DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(2 * 1000), HandleRestart, nullptr);
DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(CONFIG_OTA_AUTO_REBOOT_DELAY_MS), HandleRestart, nullptr);
#else
ESP_LOGI(TAG, "Please reboot the device manually to apply the new image");
#endif
}

CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)
Expand Down

0 comments on commit 9fbcf1c

Please sign in to comment.