Over-The-Air(OTA) Upgrader

Introduction

This architecture-agnostic component adds support for Over-The-Air upgrades.

Usage

  1. Add COMPONENT_DEPENDS += Ota to your application component.mk file.

  2. Add these lines to your application:

    #include <Ota/Manager.h>
    

After that you will have access to a global OtaManager instance that can be used to manage your OTA upgrade process.

  1. You can use OtaManager to get information about the bootable partitions and update them. The code below will display the current bootable and running partition:

    void init()
    {
    
        // ...
        auto partition = OtaManager.getRunningPartition();
    
        Serial.printf("\r\nCurrently running %s @ 0x%08x.\r\n", partition.name().c_str(), partition.address());
    
    }
    
  2. If needed you can also create your own instance of the of OtaUpgrader as shown below:

    // Call when IP address has been obtained
    void onIp(IpAddress ip, IpAddress mask, IpAddress gateway)
    {
       // ...
    
       OtaUpgrader ota;
    
       auto part = ota.getNextBootPartition();
    
       ota.begin(part);
    
       // ... write all the data to the partition
    
       ota.end();
    
       // ...
    }
    

See the Basic Ota sample application.

API Documentation

class RbootUpgrader : public Ota::UpgraderBase

ESP8266 rBoot OTA Upgrader implementation.

class IdfUpgrader : public Ota::UpgraderBase

ESP32 OTA Upgrader implementation.

class PicoUpgrader : public Ota::UpgraderBase

RP2350 OTA Upgrader implementation.

See also Rp2040 Multi-boot / OTA updates.

class UpgraderBase

Each supported architecture implements this interface to support OTA updates.

Subclassed by Ota::IdfUpgrader, Ota::PicoUpgrader, Ota::RbootUpgrader

Public Functions

virtual bool begin(Partition partition, size_t size = 0) = 0

Prepares a partition for an upgrade. The preparation is bootloader and architecture dependent.

Parameters:
  • partition

  • size

Return values:

bool

virtual size_t write(const uint8_t *buffer, size_t size) = 0

Writes chunk of data to the partition set in begin().

Parameters:
  • buffer

  • size

Return values:

size_t – actually written bytes

virtual bool end() = 0

Finalizes the partition upgrade.

inline virtual bool abort()

Aborts a partition upgrade.

virtual bool setBootPartition(Partition partition, bool save = true) = 0

Sets the default partition from where the application will be booted on next restart.

Parameters:
  • partition

  • save – if true the change is persisted on the flash, otherwise it will be valid only for the next boot

Return values:

bool

virtual Partition getBootPartition() = 0

Gets information about the partition that is set as the default one to boot.

Note

The returned partition can be different than the current running partition.

Return values:

partition

virtual Partition getRunningPartition() = 0

Gets information about the partition from which the current application is running.

Note

The returned partition can be different than the default boot partition.

Return values:

partition

virtual Partition getNextBootPartition(Partition startFrom = {}) = 0

Gets the next bootable partition that can be used after successful OTA upgrade.

Parameters:

startFrom – - optional

Return values:

partition

inline Storage::Iterator getBootPartitions()

Gets information about all bootable partitions.

Return values:

Storage::Iterator

inline uint8_t getSlot(Partition partition)

Gets slot number for a partition.

Parameters:

partition

Return values:

uint8_t – slot number

References

Used by

Environment Variables

SoC support

  • esp8266

  • host