Skip to content

ESP-IDF integration

To get ESP-IDF OTA updates that roll back when the new firmware fails, use a partition table with two OTA app slots, set CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y, and add the wassie-dev/simpleota component. A new image then boots on trial. If it crashes, hits a watchdog reset or loses power before it confirms, the bootloader boots the previous image. If it runs but is not confirmed within the confirm timeout (300 s by default), the component marks it invalid and rolls back. In managed mode the first successful check-in confirms it; with .manual_confirm or polling mode, your call to simpleota_confirm() does. The device reports confirmed, or rolled_back with a reason, and the first rollback pauses the deployment by default. The prerequisites and minimal integration below are the full setup; the limits of the trial are listed in the rollback guide.

The recommended path is the first-party component wassie-dev/simpleota from the Espressif Component Registry. It implements the full SimpleOTA device contract: periodic checks, streaming download and flash with SHA-256 and Ed25519 signature verification, complete lifecycle status reporting, and bootloader-rollback-aware trial installs. It is the sibling of the Arduino client and uses the same simpleota.h.

If you prefer to hand-roll your integration, the manual integration appendix below documents the raw API flow.

Start from a template

Starting a new project? The ESP-IDF starter is a GitHub template, so you click Use this template to make your own copy, add your SimpleOTA and Wi-Fi settings, flash the board once over USB, and then push a version tag to ship the firmware.

If you already have a project, follow the component steps below instead.

Upgrading from 0.2.x? See Upgrading to 1.0.0.

Install

idf.py add-dependency "wassie-dev/simpleota^1.0.0"

Project prerequisites

Create the SimpleOTA project with ESP-IDF as its default framework (see Your first project). Simple-mode uploads take their framework from the project, and an ESP-IDF device is offered only ESP-IDF builds.

Save this partition table as partitions.csv in your project directory:

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     ,        0x6000,
otadata,  data, ota,     ,        0x2000,
phy_init, data, phy,     ,        0x1000,
ota_0,    app,  ota_0,   ,        1700K,
ota_1,    app,  ota_1,   ,        1700K,

Then add these lines to your project's sdkconfig.defaults:

CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y

Two OTA app slots are required for any OTA scheme. This table is the one the component's examples ship: two 1700 KB slots and no factory partition, on 4 MB of flash. A serial flash boots ota_0, and updates alternate between the two slots. On ESP-IDF 5.4 and later, CONFIG_PARTITION_TABLE_TWO_OTA_LARGE=y selects the same table. ESP-IDF's CONFIG_PARTITION_TABLE_TWO_OTA also works, but its OTA slots are 1 MB each, and an app with Wi-Fi and SimpleOTA fills most of one: on an ESP32-C6 the component's example leaves less than 5% of it free.

Bootloader rollback is strongly recommended: with it, a freshly flashed image gets exactly one attempt (crash, watchdog, or power loss before confirmation returns the device to the previous build automatically). The partition table and the bootloader settings ship with the first serial flash; they cannot be changed later over the air. To move devices to another table, see Changing the layout in the component's README.

Without CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE, 1.0.0 enables CONFIG_SIMPLEOTA_SOFTWARE_ROLLBACK by default: new images run as trials, and a reset after simpleota_init() on that boot (crash, deep sleep, or esp_restart()) before confirm rolls back like a bootloader trial would. Confirm before you call esp_restart() on purpose, or set that Kconfig option to n, which with bootloader rollback also off accepts the image on first boot as in 0.2.x. Software rollback can't catch a crash loop that never reaches simpleota_init(), which bootloader rollback does catch, so enable CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE on new devices.

A size-optimized build leaves more of each slot for your application.

ESP-IDF reads sdkconfig.defaults only when it generates sdkconfig, so delete an existing sdkconfig after adding these lines.

Minimal integration

#include "simpleota.h"

void app_main(void) {
    // nvs_flash_init(), then bring up Wi-Fi (or Ethernet) and wait for an IP:
    // the first check runs as soon as simpleota_start() is called.

    simpleota_config_t cfg = {
        .token = "YOUR_PROJECT_TOKEN",   // Project -> API tokens (device scope)
        .base_url = "https://simpleota.com",  // must be https:// with a host
        .board_id = "my-board-r1",       // match your artifact constraints
    };
    ESP_ERROR_CHECK(simpleota_init(&cfg));
    ESP_ERROR_CHECK(simpleota_start());
}

esp_wifi_start() and esp_wifi_connect() return before the station has an IP, so wait for IP_EVENT_STA_GOT_IP before calling simpleota_start(). A check without an IP fails, the component retries it once after 2 s, and the next attempt comes a full check interval later (default one hour). To make every check wait for the link, set the optional .is_connected callback as well: while it returns false the component polls it every second, and the check runs as soon as it returns true. The basic example does both.

The component starts a background task that checks on an interval (default hourly), downloads and flashes offered builds, reboots into them as a supervised trial, and reports the full lifecycle (download_started through confirmed / failed / rolled_back) so the dashboard timeline is complete. The device identifies itself with its Wi-Fi MAC by default and reports framework: "esp_idf" plus the chip family of the build target automatically.

Polling mode

Instead of simpleota_start(), call simpleota_check() and simpleota_apply() from your own task. Each call runs on a short-lived task of CONFIG_SIMPLEOTA_TASK_STACK_SIZE (default 12288) while the caller waits, so the caller's stack does not matter. event_cb runs on that task (or on the managed task when you use simpleota_start()). While the managed task runs, simpleota_check() returns ESP_ERR_INVALID_STATE and simpleota_apply() returns SIMPLEOTA_NO_OFFER. In polling mode you must call simpleota_confirm() on every trial boot; .manual_confirm applies only to managed mode. simpleota_check() still returns an offer whose build is not above the running one. simpleota_apply() returns SIMPLEOTA_DOWNGRADE and reports downgrade_refused before it downloads. simpleota_check() can return ESP_ERR_NO_MEM when that task cannot be created, and simpleota_apply() returns SIMPLEOTA_FLASH_FAIL in that case with the offer kept.

Anti-rollback and image_build

simpleota_apply() refuses an offer at or below the running build before any download. A check does not. To go back to known-good firmware you upload it again and SimpleOTA gives it a new, higher build number. If you also ship release images over USB, set .image_build in simpleota_config_t (default 0) to the build number SimpleOTA assigned on upload so check-ins report it, and reflashing the same image keeps the stored build.

simpleota_set_server_url() follows the same https:// with a host rule as base_url, and simpleota_last_offered_version() returns the version label from the last offer.

Rollback

With CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE, a freshly flashed image boots as PENDING_VERIFY and gives the new image one boot attempt before it rolls back: a crash, watchdog reset, or power loss before confirmation returns the device to the previous build automatically. On top of that the component runs a confirm timeout (default 300 s): an image that runs but is not confirmed in time is marked invalid and rolled back, reported as rolled_back / confirm_timeout. After any rollback the previous build number is restored in NVS so the server can re-offer a fixed build.

Confirmation is automatic on the first successful check-in after a trial boot when .manual_confirm is false (managed mode). If your application has its own health checks, set .manual_confirm = true and call simpleota_confirm() once they pass. If the bootloader cannot mark the image valid, simpleota_confirm() returns ESP_FAIL and the trial keeps running, so call it again. Polling mode always needs simpleota_confirm(), whatever .manual_confirm is set to.

Signed firmware

Pin your project's public key and enforce signed updates:

static const char *PUBKEY_PEM =
    "-----BEGIN PUBLIC KEY-----\n"
    "...from the dashboard's Signing keys section...\n"
    "-----END PUBLIC KEY-----\n";

const simpleota_signing_key_t keys[] = {{.key_id = "prod-2026", .pem = PUBKEY_PEM}};
simpleota_config_t cfg = {
    .token = "...",
    .security_mode = SIMPLEOTA_SECURITY_SIGNED,
    .signing_keys = keys,
    .num_signing_keys = 1,
};

Every offered image is then verified against the pinned key during download, before the partition is marked bootable. A missing, stripped, or invalid signature rejects the update (failed / signature_invalid) and the device stays on its current build. See the signed firmware guide for key creation, CI signing, rotation, and the basic -> signed fleet migration recipe (identical for Arduino and ESP-IDF).

TLS

The component uses the ESP-IDF certificate bundle by default (CONFIG_MBEDTLS_CERTIFICATE_BUNDLE, on by default), so there is no CA certificate to embed or rotate. Pin a specific CA with .cert_pem if your policy requires it.

Examples

The component ships three example projects, also usable as templates via idf.py create-project-from-example (for example "wassie-dev/simpleota:basic"):

  • basic: managed updates with bootloader rollback.
  • polling: simpleota_check() and simpleota_apply() on your schedule.
  • signed: on-device Ed25519 verification with a pinned key.

Appendix: manual integration

The raw device API is small and hand-rolling a client is entirely supported; this is what the component does internally.

  1. POST /api/v1/ota/check/ with Authorization: Bearer <token> and a JSON body carrying device_id, framework: "esp_idf", chip_family, current_build_number (0 for a factory-fresh device), and any compatibility fields your artifacts constrain (board_id, hardware_revision, partition_profile, nvs_schema_version, security_mode, channel).
  2. When the response has update_available: true, stream the pre-signed url into the inactive OTA partition (esp_ota_begin / esp_ota_write), hashing as you go, and compare against checksum (SHA-256 hex) before esp_ota_end + esp_ota_set_boot_partition. Do not send the bearer token to the download URL.
  3. Report lifecycle events to POST /api/v1/ota/status/ (device_id, deployment_id from the offer, event, build_number, optional reason). The event vocabulary, ordering, and reason tokens are documented in the device API reference; note that confirmed (not success) is the terminal success event, and unknown events are rejected with HTTP 400.
  4. Persist the offered build_number (NVS) and send it as current_build_number on subsequent checks; after a rollback, restore the previous build number or the server will consider the device up to date and never re-offer a fix.
  5. For rollback, prefer CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE + esp_ota_mark_app_valid_cancel_rollback() once the new image proves healthy, and esp_ota_mark_app_invalid_rollback_and_reboot() when it does not.

For signed firmware in a hand-rolled client, see the manual verification appendix of the signed firmware guide.