Skip to content

Rollback

A new image boots on trial, and if the device confirms it inside the confirm window, the image stays. A crash, a reset, a hang, or a window that runs out boots the previous image instead, apart from the cases listed under Limits. The device then reports confirmed, or rolled_back with a reason.

Pausing the deployment stops further offers, and republishing the previous binary as a higher build is how devices move back to it. Pausing deployments covers both.

Install steps are in Arduino integration and ESP-IDF integration. The client API is in the Arduino README and the ESP-IDF README.

Trial boot

On Arduino the library saves a trial record before simpleota_apply() switches the boot slot, so a power cut leaves either the old image running or the new image on trial. ESP-IDF saves that record, including the new build's identity, before the boot slot switches.

On Arduino the library defines verifyRollbackLater(), so the bootloader holds a SimpleOTA trial on probation until simpleota_confirm(). A crash or reset before that call, including inside a global constructor or early in setup(), returns to the previous firmware on the next boot. An image written by another updater is accepted as usual.

On ESP-IDF the same protection comes from CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE. The new image boots as PENDING_VERIFY, and a crash or power loss before confirmation returns to the previous app. Put that option in the first serial flash, because a later OTA update cannot add it. If the option is absent, 1.0.0 still runs new images as trials: CONFIG_SIMPLEOTA_SOFTWARE_ROLLBACK defaults to y, so a reset after simpleota_init() on that boot before confirm rolls back like a bootloader trial would. With both bootloader rollback and software rollback off, a new image is accepted on first boot without a trial (as in 0.2.x). Software rollback can't catch a crash loop that never reaches simpleota_init().

During a trial the client skips further downloads, so the other slot keeps the previous image. simpleota_apply() returns SIMPLEOTA_UNCONFIRMED and keeps the offer.

%%{init: {"flowchart": {"rankSpacing": 35, "nodeSpacing": 20}}}%%
flowchart TD
    A["New image boots on trial"] --> B{"Confirmed before the window ends?"}
    B -- Yes --> C["Report confirmed"]
    B -- "Crash, reset, hang, or timeout" --> D["Previous image boots"]
    D --> E["Report rolled_back with a reason"]

Confirming

The window defaults to 300 seconds and is clamped to 10 through 86400.

On Arduino, set cfg.confirm_timeout_s before simpleota_init() in managed mode, or before the first simpleota_check(), simpleota_apply(), simpleota_is_trial_boot(), or simpleota_confirm() in polling mode. On ESP-IDF, set confirm_timeout_s. Passing 0 uses the 300 second default.

The default assumes Wi-Fi, so for cellular or other links where attaching, registering, and reaching the API can take several minutes, raise confirm_timeout_s in simpleota_config_t on both Arduino and ESP-IDF.

Transport Suggested timeout
Wi-Fi, fast network 60-120 s
Wi-Fi, enterprise or captive portal 180-300 s
Cellular (LTE-M or NB-IoT) 300-600 s

Set the timeout to the worst case from power-on to a healthy application, with margin. If in doubt, use the default.

Managed mode, the default

Managed mode on Arduino (with default manual_confirm) confirms the trial on the first HTTP 2xx from /api/v1/ota/check/, which shows that boot, the network, TLS, and the token worked, though not that the rest of your application is healthy. For that, use manual confirm below.

simpleota_start() on ESP-IDF confirms the trial on the first HTTP 2xx from /api/v1/ota/check/ when .manual_confirm is false. That shows the same things it does on Arduino, so to confirm on your own health check instead, set .manual_confirm and call simpleota_confirm().

simpleota_config_t cfg = {};
cfg.token = "YOUR_PROJECT_TOKEN";
cfg.is_connected = wifiUp;
cfg.check_interval_s = 3600;
simpleota_init(&cfg);
simpleota_start();
simpleota_config_t cfg = { .token = "YOUR_PROJECT_TOKEN" };
ESP_ERROR_CHECK(simpleota_init(&cfg));
ESP_ERROR_CHECK(simpleota_start());

Manual confirm

Turn auto-confirm off and confirm from your own health check.

Arduino, managed mode:

simpleota_config_t cfg = {};
cfg.token = "YOUR_PROJECT_TOKEN";
cfg.manual_confirm = true;
cfg.confirm_timeout_s = 120;
cfg.is_connected = wifiUp;
simpleota_init(&cfg);
simpleota_start();

if (simpleota_is_trial_boot() && applicationHealthy()) {
    simpleota_confirm();
}

In polling mode the library leaves confirmation to you. Call simpleota_confirm() once the application is working. A natural place is the top of loop():

void loop() {
    if (WiFi.status() != WL_CONNECTED) connectWiFi();
    simpleota_confirm();
    bool update = false;
    if (simpleota_check(&update) == ESP_OK && update) simpleota_apply();
    delay(3600UL * 1000UL);
}

If that call is skipped, every update rolls back when the window ends.

ESP-IDF:

simpleota_config_t cfg = {
    .token = "YOUR_PROJECT_TOKEN",
    .manual_confirm = true,
};
// Once your health checks pass:
simpleota_confirm();

Both clients mark the image valid in the bootloader first (or the software-rollback equivalent when bootloader rollback is off). When that step fails, simpleota_confirm() returns ESP_FAIL and the trial keeps running, so call it again.

On ESP-IDF without CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE, 1.0.0 defaults to software rollback, so once simpleota_init() has run on the trial boot, a crash, deep sleep or esp_restart() before confirm ends the trial the same way. It can't catch a crash loop that never reaches simpleota_init(), which bootloader rollback does catch. Confirm before you call esp_restart() on purpose, or disable CONFIG_SIMPLEOTA_SOFTWARE_ROLLBACK.

Hangs and deep sleep

A hang that also stops the confirm timer is reset by the chip's RTC or LP watchdog. On Arduino that watchdog starts inside verifyRollbackLater(), before setup(), for the compile-time confirm time, then restarts with this instance's timeout when the library first runs. On ESP-IDF, simpleota_init() starts it on a trial boot, so call that as soon as NVS is ready. The report reason is watchdog. Confirming stops the watchdog.

Deep sleep before confirm ends the trial, and the device wakes on the previous image, so confirm before the first sleep after an update. The reason is deep_sleep on ESP-IDF, including when CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP is set, and on Arduino core 3.x, where the watchdog stops before sleep. On Arduino core 2.x a sleep longer than the rest of the confirm time ends in a watchdog reset, and the trial still rolls back.

After a rollback, each client restores the previous build number in NVS, along with the stored hash and version label when those were saved for the trial. The rolled_back reason is confirm_timeout when the window runs out. Otherwise it names the reset that ended the trial: panic, int_wdt, task_wdt, watchdog, brownout, power_on, deep_sleep, or reset. On ESP-IDF, reset is also the reason when the bootloader refuses the image.

Dashboard

A confirmed report counts toward the deployment's confirmed total. A rollback shows on the device row as Rolled back, will retry while the device has a retry left, or Rolled back when it has none, along with its reason. The device timeline labels that step Rolled back with the same reason, and rolled-back devices count toward Failed / RB.

Auto-pause is on by default with a threshold of 1, so the first rolled_back report pauses the deployment, and a paused deployment is not offered on /check/ until you resume or cancel it (Pausing deployments has the details). The pause emails the creator, or the project owner when the release came from a project token, if that account has a verified address. The deployment form and the deployment detail page both have the auto-pause checkbox, the pause threshold and Retries allowed under Rollback safety. Retries allowed is 1 by default, so a device that rolls back is offered this deployment one more time, and 0 means the device is never offered this deployment again after a rollback. Raising the pause threshold lets more than one rollback through before the pause, and that count starts over each time you resume. Deployments started from simple mode, a quick release or the developer API use the defaults, which are auto-pause on, a threshold of 1 and 1 retry.

Resume or cancel from the deployment page. After a resume, a device that rolled back and still has a retry left is offered this deployment again, and any device can still get a different deployment with a higher build number. That same guide covers republishing a known-good binary at a higher build number.

Anti-rollback vs trial rollback

Refusing to install an offer whose build number is not above the running build is a different thing from trial rollback. The device sees SIMPLEOTA_DOWNGRADE, and the server sees failed with reason downgrade_refused. To move devices off a bad release number, pause the deployment and ship the fixed or previous firmware as a new upload with a higher build. See Build numbers and Upgrading to 1.0.0.

Limits

  • A hang in an Arduino global constructor happens before the watchdog starts, so nothing resets the chip. A crash there still rolls back.
  • A sketch that defines its own verifyRollbackLater() has to build with -DSIMPLEOTA_DISABLE_BOOTLOADER_ROLLBACK, which only skips defining verifyRollbackLater(). The trial watchdog keeps running unless you also set -DSIMPLEOTA_DISABLE_TRIAL_WATCHDOG. From simpleota_init() onward on that boot, the library rolls back on its own after the confirm timeout or any reset before confirm (crash, watchdog, brownout, power loss, ESP.restart() or deep sleep), but an image that crashes before simpleota_init() on every boot is never rolled back.
  • On Arduino, a partition table with one app slot makes simpleota_apply() report update_begin_failed (via SIMPLEOTA_EVENT_UPDATE_FAILED).
  • On ESP-IDF, a new image runs without a trial only when both CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE and CONFIG_SIMPLEOTA_SOFTWARE_ROLLBACK are off. Without bootloader rollback, a crash loop that never reaches simpleota_init() isn't caught. The ESP-IDF guide shows the first serial flash sdkconfig.defaults lines.