Arduino integration¶
ArduinoOTA updates an ESP32 only from a computer on the same local network.
To update boards over the internet, add the first-party SimpleOTAClient
library to the sketch. The board checks in with SimpleOTA over HTTPS (hourly
by default). When you deploy a new build, it downloads the binary from a
short-lived pre-signed URL, checks its SHA-256, and reboots into it on trial.
If the new build crashes or never confirms, the board boots the previous
firmware. The first flash still goes over USB; updates after that arrive over
the air. The managed-mode sketch below is the whole
integration. To ship a build, upload the application binary (<sketch>.ino.bin
from Arduino IDE or CLI, firmware.bin from PlatformIO) in the dashboard or
from CI.
Version 1.0.0 ships the same simpleota.h C API as the ESP-IDF
component.
Start from a template¶
Starting a new sketch? The Arduino 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 sketch, follow the library steps below instead.
SimpleOTAClient library¶
Repository: https://github.com/wassie-dev/simpleOTAClient-Arduino
The library README is the canonical reference for the full API, timing knobs, callback hooks, and limitations. The quick-start below is the minimum to get a device receiving updates on 1.0.0. Upgrading from 0.6.x? See Upgrading to 1.0.0.
Install¶
In the IDE: Sketch > Include Library > Manage Libraries... Search for SimpleOTAClient, pick version 1.0.0, and click Install.
To install from a release tag when the Library Manager is unavailable, download the 1.0.0 zip from the Releases page and use Sketch > Include Library > Add .ZIP Library...
Managed-mode sketch¶
The library runs checks on a background task (default interval one hour) and handles download, flash, reboot, and auto-confirm on the first successful check-in after a trial boot.
#include <WiFi.h>
#include <simpleota.h>
const char* PROJECT_TOKEN = "soto_proj_xxxxxxxxxxxxxxxx";
const char* WIFI_SSID = "your-ssid";
const char* WIFI_PASS = "your-password";
static bool wifiUp(void*) { return WiFi.status() == WL_CONNECTED; }
void setup() {
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(250);
simpleota_config_t cfg = {};
cfg.token = PROJECT_TOKEN;
cfg.version_label = "1.0.0";
cfg.is_connected = wifiUp;
cfg.check_interval_s = 3600;
if (simpleota_init(&cfg) != ESP_OK || simpleota_start() != ESP_OK) {
Serial.println("SimpleOTA did not start; see the log above");
}
}
void loop() {}
Call simpleota_init() early in setup(): on a trial boot the confirm
timeout starts there.
Polling mode¶
Use simpleota_check() and simpleota_apply() when you want to control
exactly when updates happen (for example, only while on mains power). In
polling mode you must call simpleota_confirm() yourself, otherwise
every OTA rolls back after the confirm timeout (default 300 s). Polling and
managed mode do not mix: call simpleota_stop() before polling, or skip
simpleota_start() entirely. Each simpleota_check() and simpleota_apply()
runs on a short-lived task of CONFIG_SIMPLEOTA_TASK_STACK_SIZE (default
12288) while your code waits, so your loop's stack does not matter.
event_cb runs on that task (or on the managed task when you use
simpleota_start()). 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.
void loop() {
if (WiFi.status() != WL_CONNECTED) connectWiFi();
simpleota_confirm();
bool update = false;
if (simpleota_check(&update) == ESP_OK && update) {
simpleota_result_t r = simpleota_apply();
if (r == SIMPLEOTA_DOWNGRADE) { /* offer not above running build */ }
}
delay(3600UL * 1000UL);
}
Targeting specific hardware¶
Set optional fields on simpleota_config_t before simpleota_init():
simpleota_config_t cfg = {};
cfg.token = PROJECT_TOKEN;
cfg.chip_family = "esp32s3"; // defaults to the build target
cfg.device_id = "kitchen-sensor-01";
cfg.board_id = "feather-s3";
cfg.hardware_revision = "rev-b";
simpleota_init(&cfg);
Lifecycle events (event_cb)¶
Set cfg.event_cb before simpleota_init() to observe checks, download
progress, failures (with a reason string such as signature_invalid or
downgrade_refused), reboot, and trial confirm or rollback:
void onOtaEvent(const simpleota_event_t *e, void *) {
if (e->id == SIMPLEOTA_EVENT_UPDATE_FAILED && e->reason) {
Serial.println(e->reason);
}
}
cfg.event_cb = onOtaEvent;
Keep the handler short and do not call back into the client from it except
simpleota_reboot_for_update() when disable_auto_reboot is set.
Anti-rollback¶
Before any download, the client refuses offers whose build_number is not
strictly above the running build. simpleota_apply() returns
SIMPLEOTA_DOWNGRADE, the server receives failed with reason
downgrade_refused, and there is no override. To recover from a bad
release, upload the previous binary again so SimpleOTA allocates a new,
higher build number and deploy that artifact.
USB-flashed images (image_build)¶
Firmware you flash over serial reports build 0 by default until SimpleOTA
installs an update. For a release you also ship on USB, set cfg.image_build
before simpleota_init() to the build number SimpleOTA assigned when you
uploaded that release. The value is ignored when the running image was
installed by SimpleOTA or when the same ELF fingerprint is already stored in
NVS.
HTTPS and TLS¶
cfg.base_url defaults to https://simpleota.com and must be https://
with a host. Change it before simpleota_init(), or call
simpleota_set_server_url() only while the managed task is stopped (after
simpleota_stop()). TLS verification is always on; pin a CA with
cfg.cert_pem if needed. Downloads follow up to three redirects, and each
hop must be https://.
Only one client instance is allowed per device (simpleota_init() twice
returns ESP_ERR_INVALID_STATE). In managed mode, simpleota_check_now()
wakes the background task, and simpleota_current_build() returns the build
the device reports.
To turn on debug logging, call esp_log_level_set("simpleota", ESP_LOG_DEBUG) after init.
Rollback¶
After simpleota_apply(), the new image boots as a trial until you call
simpleota_confirm() (managed mode can auto-confirm on the first successful
/check/). Use simpleota_is_trial_boot() when you want to run your own
health checks first:
A crash or reset before confirm returns the device to the previous partition
through the ESP32 bootloader. If you build with
-DSIMPLEOTA_DISABLE_BOOTLOADER_ROLLBACK, the library handles rollback in
software after simpleota_init() runs, and it can't catch a crash loop that never reaches simpleota_init(). See
Trial install and rollback for timeouts, polling mode, dashboard
reporting and the limits.
Signed firmware¶
Pin Ed25519 public keys in config and set cfg.security_mode to
SIMPLEOTA_SECURITY_SIGNED. Signed artifacts are verified over the exact
downloaded bytes before the image is marked bootable.
static const char *PUBKEY_PEM =
"-----BEGIN PUBLIC KEY-----\n"
"MCowBQYDK2VwAyEA...your project public key...\n"
"-----END PUBLIC KEY-----\n";
const simpleota_signing_key_t keys[] = {
{.key_id = "prod-2026", .pem = PUBKEY_PEM},
};
simpleota_config_t cfg = {};
cfg.token = PROJECT_TOKEN;
cfg.security_mode = SIMPLEOTA_SECURITY_SIGNED;
cfg.signing_keys = keys;
cfg.num_signing_keys = 1;
Get the public key from your project's "Firmware signing keys" section
(Advanced mode). On verification failure, simpleota_apply() returns
SIMPLEOTA_SIGNATURE_FAIL, the device keeps running its current firmware, and
the dashboard shows the device as failed / signature_invalid. During key
rotation, pin up to two keys in signing_keys. See the library's
examples/SignedOTA sketch.
Secure Boot is not available on Arduino
Stock Arduino-ESP32 cores ship precompiled bootloaders built without ESP32 Secure Boot, so hardware-rooted boot verification (protection against physical reflashing over UART/USB) cannot be enabled on the Arduino path. OTA-level signing as described here is the strongest firmware-integrity protection available on Arduino; it protects the update delivery path, not the device against physical access. If your threat model includes physical attackers, build under ESP-IDF with Secure Boot v2. See the threat model.
Migrating an existing fleet¶
Keys are compiled into the firmware, so ship one final basic upload whose
code pins the key and sets SIMPLEOTA_SECURITY_SIGNED. Devices running it
report signed mode and verify every subsequent update.
Two rules of the server's mode matching
to keep in mind: a device reporting basic is never offered a signed
artifact (so the migration build itself must be uploaded as basic), and
once devices report signed they are never offered basic artifacts (so
every upload after the migration must be signed). Blocked devices do not
error; they silently stay on their current build, so check the device list
for stragglers still reporting basic after the rollout.
Full walkthrough (key creation, CI signing, rotation): Signed firmware guide.