Over-The-Air(OTA) Network Upgrader
Introduction
This architecture-agnostic component adds support for Over-The-Air upgrades.
Usage
Add
COMPONENT_DEPENDS += Ota
to your application component.mk file.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.
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()); }
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 partition = ota.getNextBootPartition(); ota.begin(partition); // ... write all the data to the partition ota.end(); // ... }
See the Basic Ota sample application.
API Documentation
-
namespace Network
Variables
-
constexpr uint8_t NO_ROM_SWITCH = {0xff}
Magic value for ROM slot indicating slot won’t change after successful OTA.
-
class HttpUpgrader : protected HttpClient
- #include <HttpUpgrader.h>
Public Functions
-
inline bool addItem(const String &firmwareFileUrl, Partition partition, ReadWriteStream *stream = nullptr)
Add an item to update.
- Parameters:
firmwareFileUrl –
partition – Target partition to write
stream –
- Return values:
bool –
-
inline void switchToRom(uint8_t romSlot)
On completion, switch to the given ROM slot.
- Parameters:
romSlot – specify NO_ROM_SWITCH (the default) to cancel any previously set switch
-
inline void setBaseRequest(HttpRequest *request)
Sets the base request that can be used to pass.
- default request parameters, like request headers... - default SSL options - default SSL fingeprints - default SSL client certificates
- Parameters:
request –
-
inline const ItemList &getItems() const
Allow read access to item list.
-
struct Item
- #include <HttpUpgrader.h>
-
inline bool addItem(const String &firmwareFileUrl, Partition partition, ReadWriteStream *stream = nullptr)
-
constexpr uint8_t NO_ROM_SWITCH = {0xff}
References
Used by
Basic Ota Sample
SoC support
esp32
esp32c2
esp32c3
esp32s2
esp32s3
esp8266
host