|
SimpleOTA client v1.1.0
Shared core of the SimpleOTA Arduino and ESP-IDF clients
|
The SimpleOTA client for ESP32, the same API in the ESP-IDF component and the Arduino library. More...
Go to the source code of this file.
Data Structures | |
| struct | simpleota_event_t |
| One lifecycle event, valid only during the event_cb call. More... | |
| struct | simpleota_signing_key_t |
| A pinned Ed25519 public key for signed-firmware verification. More... | |
| struct | simpleota_config_t |
| Configuration. More... | |
Macros | |
API version | |
The version of this API, not of either package: the minor version grows when something is added, the major one only for a breaking change. Both the Arduino library and the ESP-IDF component ship this header unchanged. #if SIMPLEOTA_API_VERSION >= SIMPLEOTA_API_VERSION_NUM(1, 1)
// use something added in 1.1
#endif
| |
| #define | SIMPLEOTA_API_VERSION_MAJOR 1 |
| Breaking changes. | |
| #define | SIMPLEOTA_API_VERSION_MINOR 1 |
| Additions. | |
| #define | SIMPLEOTA_API_VERSION_NUM(major, minor) ((major) * 1000 + (minor)) |
| A version as one comparable number. | |
| #define | SIMPLEOTA_API_VERSION SIMPLEOTA_API_VERSION_NUM(SIMPLEOTA_API_VERSION_MAJOR, SIMPLEOTA_API_VERSION_MINOR) |
| This header's version, as SIMPLEOTA_API_VERSION_NUM() gives it. | |
Enumerations | |
| enum | simpleota_security_t { SIMPLEOTA_SECURITY_NONE = 0 , SIMPLEOTA_SECURITY_BASIC , SIMPLEOTA_SECURITY_SIGNED } |
| The security mode a device reports on check-ins. More... | |
| enum | simpleota_result_t { SIMPLEOTA_OK = 0 , SIMPLEOTA_CHECKSUM_FAIL = 1 , SIMPLEOTA_FLASH_FAIL = 2 , SIMPLEOTA_NO_OFFER = 3 , SIMPLEOTA_SIGNATURE_FAIL = 4 , SIMPLEOTA_REBOOT_PENDING = 5 , SIMPLEOTA_UNCONFIRMED = 6 , SIMPLEOTA_DOWNGRADE = 7 } |
| What simpleota_apply() did. More... | |
| enum | simpleota_event_id_t { SIMPLEOTA_EVENT_CHECK_DONE , SIMPLEOTA_EVENT_UPDATE_AVAILABLE , SIMPLEOTA_EVENT_DOWNLOAD_PROGRESS , SIMPLEOTA_EVENT_UPDATE_FAILED , SIMPLEOTA_EVENT_BEFORE_REBOOT , SIMPLEOTA_EVENT_TRIAL_BOOT , SIMPLEOTA_EVENT_CONFIRMED , SIMPLEOTA_EVENT_ROLLING_BACK } |
| Events delivered to simpleota_config_t::event_cb. More... | |
Functions | |
| esp_err_t | simpleota_init (const simpleota_config_t *config) |
| Initialize the client: copy config, apply defaults, parse and pin signing keys, load persisted state, and run boot-time trial validation (detects rollbacks, arms the confirm timeout for trial boots). | |
| esp_err_t | simpleota_start (void) |
| Start the managed background task: check on the interval, apply what is offered, confirm a trial on its first successful check-in (unless manual_confirm), and post reports. | |
| esp_err_t | simpleota_stop (void) |
| Stop the managed task. | |
| esp_err_t | simpleota_check_now (void) |
| Wake the managed task to check immediately. | |
| esp_err_t | simpleota_check (bool *update_available) |
| Polling mode: check in, and keep any offer for simpleota_apply(). | |
| simpleota_result_t | simpleota_apply (void) |
| Polling mode: download, verify and flash the offer from the last simpleota_check(), then reboot unless disable_auto_reboot is set. | |
| esp_err_t | simpleota_set_server_url (const char *url) |
| Point check-ins and status posts at another SimpleOTA server. | |
| const char * | simpleota_last_offered_version (void) |
| esp_err_t | simpleota_confirm (void) |
| Confirm the running trial image, after the app's own health checks pass (manual_confirm, or polling mode). | |
| esp_err_t | simpleota_reboot_for_update (void) |
| Reboot into a downloaded update when disable_auto_reboot was set. | |
| bool | simpleota_is_trial_boot (void) |
| uint32_t | simpleota_current_build (void) |
| esp_err_t | simpleota_deinit (void) |
| Stop the managed task if needed and release all resources. | |
The SimpleOTA client for ESP32, the same API in the ESP-IDF component and the Arduino library.
Thin client for the SimpleOTA firmware update platform (https://simpleota.com). Polls the check endpoint, streams and flashes offered firmware with on-the-fly SHA-256 and Ed25519 signature verification, reports lifecycle events, and runs every new image as a trial that rolls back unless it is confirmed.
The application owns network bring-up (Wi-Fi/Ethernet) and decides when the client may talk to the network via the optional is_connected callback; the client does the rest from its own background task (managed mode). In polling mode the application calls simpleota_check() and simpleota_apply() from its own task instead, and confirms a trial with simpleota_confirm(). Each runs on a short-lived task with CONFIG_SIMPLEOTA_TASK_STACK_SIZE while the caller waits, so the caller's stack size does not matter.
Quick start:
The device needs a partition table with two OTA app slots, which Arduino-ESP32's default has. On ESP-IDF, rollback by the bootloader needs CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y, which Arduino-ESP32 sets. Both ship with the first serial flash and cannot change over OTA. Without bootloader rollback the client rolls a failed trial back itself (CONFIG_SIMPLEOTA_SOFTWARE_ROLLBACK): on the confirm timeout, or on any reset before the confirm, as the bootloader would. It cannot catch an image that crashes before simpleota_init() on every boot.
The client is a process-wide singleton (one instance per device); a second simpleota_init() returns ESP_ERR_INVALID_STATE.
Thread-safety: configure and init from one task. After init the public functions are safe to call from any task, except that polling mode and simpleota_set_server_url() belong to one task of the application's.
Logs use the tag "simpleota". Warnings and errors show by default; esp_log_level_set("simpleota", ESP_LOG_DEBUG) after simpleota_init() shows every step.
Compatibility, which every later 1.x release keeps:
{0} keeps building and keeps its behaviour.reason tokens listed at simpleota_event_t are stable. New tokens may be added, so treat an unknown one as a generic failure. | enum simpleota_security_t |
The security mode a device reports on check-ins.
The server offers it only artifacts of the same mode, or any artifact when it reports none.
| enum simpleota_result_t |
What simpleota_apply() did.
The values are stable across releases.
| Enumerator | |
|---|---|
| SIMPLEOTA_OK | Flashed and verified; the reboot is next. |
| SIMPLEOTA_CHECKSUM_FAIL | The download did not match its SHA-256. |
| SIMPLEOTA_FLASH_FAIL | Network, URL, flash or state write failure. |
| SIMPLEOTA_NO_OFFER | No offer from a successful simpleota_check(). |
| SIMPLEOTA_SIGNATURE_FAIL | Required signature missing or wrong. |
| SIMPLEOTA_REBOOT_PENDING | A flashed update waits for simpleota_reboot_for_update(). |
| SIMPLEOTA_UNCONFIRMED | The running image is on trial: confirm it, then apply again. The offer is kept. |
| SIMPLEOTA_DOWNGRADE | The offered build is not above the running one; refused (anti-rollback). |
| enum simpleota_event_id_t |
Events delivered to simpleota_config_t::event_cb.
| Enumerator | |
|---|---|
| SIMPLEOTA_EVENT_CHECK_DONE | A check completed; no update offered. reason: the server's status. |
| SIMPLEOTA_EVENT_UPDATE_AVAILABLE | An update was offered. The managed task downloads it next, unless a trial runs. |
| SIMPLEOTA_EVENT_DOWNLOAD_PROGRESS | bytes_done / bytes_total advanced. |
| SIMPLEOTA_EVENT_UPDATE_FAILED | Update aborted; reason carries the token. |
| SIMPLEOTA_EVENT_BEFORE_REBOOT | Flashed + verified. Restart is imminent, or deferred until simpleota_reboot_for_update() when disable_auto_reboot is set. |
| SIMPLEOTA_EVENT_TRIAL_BOOT | Running an unconfirmed (trial) image. |
| SIMPLEOTA_EVENT_CONFIRMED | The trial image's confirmed report was delivered. |
| SIMPLEOTA_EVENT_ROLLING_BACK | The trial failed; the previous image starts next. reason says why. |
| esp_err_t simpleota_init | ( | const simpleota_config_t * | config | ) |
Initialize the client: copy config, apply defaults, parse and pin signing keys, load persisted state, and run boot-time trial validation (detects rollbacks, arms the confirm timeout for trial boots).
Call it as early as possible, after nvs_flash_init() (Arduino-ESP32 has already called it): on a trial boot the confirm timeout starts here.
| config | The configuration; copied, so it need not outlive the call. |
| ESP_OK | Ready. |
| ESP_ERR_INVALID_ARG | A missing token or one with control characters, an unparseable signing key, a security_mode out of range or SIGNED without a key, a base_url that is not https://, or a signing key or SIGNED in a build without signed updates. |
| ESP_ERR_INVALID_STATE | Already initialized, or neither the certificate bundle nor a cert_pem is available. |
| ESP_ERR_NO_MEM | Out of memory. |
| esp_err_t simpleota_start | ( | void | ) |
Start the managed background task: check on the interval, apply what is offered, confirm a trial on its first successful check-in (unless manual_confirm), and post reports.
On a trial boot the confirm timeout rolls back also without the task. Calling it again does nothing.
| ESP_OK | Running. |
| ESP_ERR_INVALID_STATE | Not initialized. |
| ESP_ERR_NO_MEM | The task could not be created. |
| esp_err_t simpleota_stop | ( | void | ) |
Stop the managed task.
Waits for its current step, up to 60 s, so a download or flash write is never cut short.
| ESP_OK | Stopped, or was not running. |
| ESP_ERR_TIMEOUT | The task is still running after 60 s. |
| esp_err_t simpleota_check_now | ( | void | ) |
Wake the managed task to check immediately.
| ESP_OK | The task was woken. |
| ESP_ERR_INVALID_STATE | The managed task is not running. |
| esp_err_t simpleota_check | ( | bool * | update_available | ) |
Polling mode: check in, and keep any offer for simpleota_apply().
Sends queued reports first, except during a trial.
| [out] | update_available | Set to true when an update is offered, and to false otherwise, whatever is returned. |
| ESP_OK | The server answered. An offer it sent that cannot be used logs a warning and counts as no update. |
| ESP_FAIL | No response, or not a 2xx: try again later. |
| ESP_ERR_INVALID_ARG | update_available is NULL. |
| ESP_ERR_INVALID_STATE | Not initialized, or (with a warning) the managed task runs. |
| ESP_ERR_NO_MEM | No memory for the task the check runs on. |
| simpleota_result_t simpleota_apply | ( | void | ) |
Polling mode: download, verify and flash the offer from the last simpleota_check(), then reboot unless disable_auto_reboot is set.
| esp_err_t simpleota_set_server_url | ( | const char * | url | ) |
Point check-ins and status posts at another SimpleOTA server.
Firmware downloads still use the offer's pre-signed URL. Not while simpleota_check() or simpleota_apply() runs on another task.
| url | The new base URL; same rules as base_url: https:// with a host. |
| ESP_OK | Switched. |
| ESP_ERR_INVALID_ARG | Rejected; the previous URL is kept. |
| ESP_ERR_INVALID_STATE | Before init, or while the managed task runs. |
| ESP_ERR_NO_MEM | Out of memory; the previous URL is kept. |
| const char * simpleota_last_offered_version | ( | void | ) |
| esp_err_t simpleota_confirm | ( | void | ) |
Confirm the running trial image, after the app's own health checks pass (manual_confirm, or polling mode).
Marks the image valid in the bootloader, cancels the confirm timer, and queues the "confirmed" report.
| ESP_OK | Confirmed, or there is no trial. |
| ESP_FAIL | The bootloader could not record the image as good; the trial keeps running, so call again. |
| ESP_ERR_INVALID_STATE | Not initialized. |
| esp_err_t simpleota_reboot_for_update | ( | void | ) |
Reboot into a downloaded update when disable_auto_reboot was set.
Until then the client does not download another update, because the next update slot holds the one waiting for this reboot.
Stops the background task, posts the "reboot" status from a short-lived task with CONFIG_SIMPLEOTA_TASK_STACK_SIZE (so any caller's stack is enough), and restarts.
| ESP_ERR_INVALID_STATE | No update is waiting. Otherwise it does not return. |
| bool simpleota_is_trial_boot | ( | void | ) |
| uint32_t simpleota_current_build | ( | void | ) |
| esp_err_t simpleota_deinit | ( | void | ) |
Stop the managed task if needed and release all resources.
Mainly for tests.
| ESP_OK | Released; simpleota_init() may run again. |
| ESP_ERR_TIMEOUT | The task did not stop; nothing is released. |
| ESP_ERR_INVALID_STATE | Called from event_cb on the managed task. |