Over-The-Air Updates

Example Usage

// Setup basic OTA
// Enable safe mode.
// OTA password
auto *ota = App.init_ota();
// OTA MD5 password
auto *ota = App.init_ota();

API Reference


class OTAComponent : public Component

OTAComponent provides a simple way to integrate Over-the-Air updates into your app using ArduinoOTA.

Public Functions

OTAComponent(uint16_t port = OTA_DEFAULT_PORT)

Construct an OTAComponent.

Defaults to no authentication.

  • port: The port ArduinoOTA will listen on.

void set_auth_password(const std::string &password)

Set a plaintext password that OTA will use for authentication.

Warning: This password will be stored in plaintext in the ROM and can be read by intruders.

  • password: The plaintext password.

void set_auth_plaintext_password(const std::string &password)

Set a plaintext password for legacy OTA.

  • password: The password

void set_auth_password_hash(const std::string &hash)

Set a hashed password for legacy OTA.

  • password: The MD5 password hash.

void set_port(uint16_t port)

Manually set the port OTA should listen on.

void start_safe_mode(uint8_t num_attempts = 10, uint32_t enable_time = 120000)

Start OTA safe mode.

When called at startup, this method will automatically detect boot loops.

If a boot loop is detected (by num_attempts boots which each lasted less than enable_time), this method will block startup and enable just WiFi and OTA so that users can flash a new image.

When in boot loop safe mode, if no OTA attempt is made within enable_time milliseconds, the device is restarted. If the device has stayed on for more than enable_time milliseconds, the boot is considered successful and the num_attempts counter is reset.

  • num_attempts: The number of failed boot attempts until which time safe mode should be enabled.
  • enable_time: The time in ms safe mode should be on before restarting.

void setup()
void dump_config()
float get_setup_priority() const
void loop()
uint16_t get_port() const
void clean_rtc()

Protected Types

enum [anonymous]



Protected Functions

void write_rtc_(uint8_t val)
uint8_t read_rtc_()
void handle_()
size_t wait_receive_(uint8_t *buf, size_t bytes, bool check_disconnected = true)

Protected Attributes

OTAComponent::[anonymous] OPEN
std::string password_
uint16_t port_
WiFiServer *server_ = {nullptr}
WiFiClient client_ = {}
bool ota_triggered_ = {false}
bool has_safe_mode_ = {false}

stores whether safe mode can be enabled.

uint32_t safe_mode_start_time_

stores when safe mode was enabled.

uint32_t safe_mode_enable_time_ = {60000}

The time safe mode should be on for.

uint8_t safe_mode_rtc_value_
uint8_t safe_mode_num_attempts_
uint8_t at_ota_progress_message_ = {0}

store OTA progress message index so that we don’t spam logs

ESPPreferenceObject rtc_