Skip to content

Commit

Permalink
[ESP32] Schedule the restart once OTA image apply is successful
Browse files Browse the repository at this point in the history
Also, Apply suggestion from project-chip#13484 in lighting-app
  • Loading branch information
shubhamdp committed Jan 20, 2022
1 parent 1607617 commit 55120ad
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
17 changes: 12 additions & 5 deletions examples/lighting-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -154,10 +154,17 @@ 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
```

Alternate way to query an OTA image using chip-tool

```
./out/debug/chip-tool otasoftwareupdaterequestor announce-ota-provider 12346 0 0 0 12345 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.
4 changes: 1 addition & 3 deletions examples/lighting-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions examples/ota-requestor-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ chip-tool. On receiving this command OTA requestor will query for OTA image.

## 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.

## ESP32 OTA Requestor with Linux OTA Provider

Expand Down
11 changes: 11 additions & 0 deletions src/platform/ESP32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@
#include "lib/core/CHIPError.h"

#define TAG "OTAImageProcessor"
using namespace chip::System;
using namespace ::chip::DeviceLayer::Internal;

namespace chip {
namespace {

void HandleRestart(Layer * systemLayer, void * appState)
{
esp_restart();
}
} // namespace

CHIP_ERROR OTAImageProcessorImpl::PrepareDownload()
{
Expand Down Expand Up @@ -168,6 +176,9 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
return;
}
ESP_LOGI(TAG, "Applying, Boot partition set offset:0x%x", imageProcessor->mOTAUpdatePartition->address);

// HandleApply is called after delayed action time seconds are elapsed, so it would be safe to schedule the restart
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(2 * 1000), HandleRestart, nullptr);
}

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

0 comments on commit 55120ad

Please sign in to comment.