SimpleOTA client v1.2.0
Shared core of the SimpleOTA Arduino and ESP-IDF clients
Loading...
Searching...
No Matches
simpleota.h
Go to the documentation of this file.
1
61#ifndef SIMPLEOTA_H
62#define SIMPLEOTA_H
63
64#include <stdbool.h>
65#include <stddef.h>
66#include <stdint.h>
67
68#include "esp_err.h"
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
86#define SIMPLEOTA_API_VERSION_MAJOR 1
87#define SIMPLEOTA_API_VERSION_MINOR 2
89#define SIMPLEOTA_API_VERSION_NUM(major, minor) ((major) * 1000 + (minor))
91#define SIMPLEOTA_API_VERSION \
92 SIMPLEOTA_API_VERSION_NUM(SIMPLEOTA_API_VERSION_MAJOR, SIMPLEOTA_API_VERSION_MINOR)
115
130
149
181typedef struct {
183 const char *reason;
185 uint32_t build_number;
186 size_t bytes_done;
187 size_t bytes_total;
190
192typedef struct {
193 const char *key_id;
194 const char *pem;
196
201typedef struct {
202 const char *token;
203 const char *base_url;
205 const char *device_id;
206 const char *chip_family;
208 const char *board_id;
209 const char *hardware_revision;
210 const char *partition_profile;
211 const char *channel;
212 const char *labels_json;
219 const char *version_label;
221 uint32_t image_build;
266 bool (*is_connected)(void *user_ctx);
271 void (*event_cb)(const simpleota_event_t *event, void *user_ctx);
272 void *user_ctx;
283 const char *cert_pem;
284 esp_err_t (*crt_bundle_attach)(void *conf);
296 bool (*can_update)(void *user_ctx);
297
311 const char *project_id;
313
337esp_err_t simpleota_init(const simpleota_config_t *config);
338
349esp_err_t simpleota_start(void);
350
358esp_err_t simpleota_stop(void);
359
366esp_err_t simpleota_check_now(void);
367
387esp_err_t simpleota_check(bool *update_available);
388
399
411esp_err_t simpleota_set_server_url(const char *url);
412
418
430esp_err_t simpleota_confirm(void);
431
445
448
454
463esp_err_t simpleota_deinit(void);
464
465#ifdef __cplusplus
466}
467#endif
468
469#endif /* SIMPLEOTA_H */
uint32_t simpleota_current_build(void)
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,...
esp_err_t simpleota_check(bool *update_available)
Polling mode: check in, and keep any offer for simpleota_apply().
simpleota_security_t
The security mode a device reports on check-ins.
Definition simpleota.h:99
@ SIMPLEOTA_SECURITY_BASIC
Unsigned artifacts, verified by checksum.
Definition simpleota.h:101
@ SIMPLEOTA_SECURITY_STRICT
SIGNED, and each update must also carry a strict signature: a second signature, made by the SimpleOTA...
Definition simpleota.h:113
@ SIMPLEOTA_SECURITY_NONE
Report none: every artifact matches.
Definition simpleota.h:100
@ SIMPLEOTA_SECURITY_SIGNED
Signed artifacts only, each verified against a pinned key before it can boot.
Definition simpleota.h:102
esp_err_t simpleota_check_now(void)
Wake the managed task to check immediately.
esp_err_t simpleota_reboot_for_update(void)
Reboot into a downloaded update when disable_auto_reboot was set.
simpleota_result_t
What simpleota_apply() did.
Definition simpleota.h:117
@ SIMPLEOTA_FLASH_FAIL
Network, URL, flash or state write failure.
Definition simpleota.h:120
@ SIMPLEOTA_DOWNGRADE
The offered build is not above the running one; refused (anti-rollback).
Definition simpleota.h:127
@ SIMPLEOTA_UNCONFIRMED
The running image is on trial: confirm it, then apply again.
Definition simpleota.h:125
@ SIMPLEOTA_REBOOT_PENDING
A flashed update waits for simpleota_reboot_for_update().
Definition simpleota.h:123
@ SIMPLEOTA_CHECKSUM_FAIL
The download did not match its SHA-256.
Definition simpleota.h:119
@ SIMPLEOTA_NO_OFFER
No offer from a successful simpleota_check().
Definition simpleota.h:121
@ SIMPLEOTA_SIGNATURE_FAIL
Required signature missing or wrong.
Definition simpleota.h:122
@ SIMPLEOTA_OK
Flashed and verified; the reboot is next.
Definition simpleota.h:118
esp_err_t simpleota_set_server_url(const char *url)
Point check-ins and status posts at another SimpleOTA server.
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,...
esp_err_t simpleota_start(void)
Start the managed background task: check on the interval, apply what is offered, confirm a trial on i...
simpleota_event_id_t
Events delivered to simpleota_config_t::event_cb.
Definition simpleota.h:132
@ SIMPLEOTA_EVENT_DOWNLOAD_PROGRESS
bytes_done / bytes_total advanced.
Definition simpleota.h:137
@ SIMPLEOTA_EVENT_ROLLING_BACK
The trial failed; the previous image starts next.
Definition simpleota.h:146
@ SIMPLEOTA_EVENT_TRIAL_BOOT
Running an unconfirmed (trial) image.
Definition simpleota.h:143
@ SIMPLEOTA_EVENT_CONFIRMED
The trial image's confirmed report was delivered.
Definition simpleota.h:144
@ SIMPLEOTA_EVENT_BEFORE_REBOOT
Flashed + verified.
Definition simpleota.h:139
@ SIMPLEOTA_EVENT_UPDATE_FAILED
Update aborted; reason carries the token.
Definition simpleota.h:138
@ SIMPLEOTA_EVENT_UPDATE_AVAILABLE
An update was offered.
Definition simpleota.h:135
@ SIMPLEOTA_EVENT_CHECK_DONE
A check completed; no update offered.
Definition simpleota.h:133
esp_err_t simpleota_deinit(void)
Stop the managed task if needed and release all resources.
bool simpleota_is_trial_boot(void)
simpleota_result_t simpleota_apply(void)
Polling mode: download, verify and flash the offer from the last simpleota_check(),...
esp_err_t simpleota_stop(void)
Stop the managed task.
Configuration.
Definition simpleota.h:201
const char * hardware_revision
Board revision.
Definition simpleota.h:209
const char * base_url
Default: "https://simpleota.com".
Definition simpleota.h:203
uint32_t check_interval_s
Seconds between checks.
Definition simpleota.h:227
uint32_t initial_delay_ms
Delay before the first check after start().
Definition simpleota.h:237
const char * version_label
Default: the label stored with the update that installed this image.
Definition simpleota.h:219
const simpleota_signing_key_t * signing_keys
Pinned public keys for signed firmware, at most 2.
Definition simpleota.h:259
const char * board_id
Board model.
Definition simpleota.h:208
const char * cert_pem
TLS trust, always verified.
Definition simpleota.h:283
const char * channel
Release channel.
Definition simpleota.h:211
uint8_t nvs_schema_version
The data schema this firmware expects.
Definition simpleota.h:226
simpleota_security_t security_mode
Default: SIMPLEOTA_SECURITY_NONE.
Definition simpleota.h:216
uint32_t confirm_timeout_s
Seconds a trial has to confirm.
Definition simpleota.h:240
const char * labels_json
Reserved: pre-formed JSON object sent verbatim on check-ins, but not yet consumed by the platform.
Definition simpleota.h:212
const char * chip_family
Default: CONFIG_IDF_TARGET ("esp32", "esp32s3", ...), the chip the firmware is built for.
Definition simpleota.h:206
const char * device_id
Default: Wi-Fi STA MAC "aa:bb:cc:dd:ee:ff".
Definition simpleota.h:205
const char * project_id
The id of the SimpleOTA project this device belongs to: the project's UUID, lowercase with hyphens,...
Definition simpleota.h:311
bool manual_confirm
Managed mode: true = the app calls simpleota_confirm(); false = the first successful check-in confirm...
Definition simpleota.h:242
uint8_t num_signing_keys
Entries in signing_keys.
Definition simpleota.h:260
const char * token
Required.
Definition simpleota.h:202
void * user_ctx
Passed to is_connected, event_cb and can_update.
Definition simpleota.h:272
bool disable_auto_reboot
true: the app calls simpleota_reboot_for_update().
Definition simpleota.h:246
const char * partition_profile
Partition layout name.
Definition simpleota.h:210
uint32_t image_build
This image's build number, reported when SimpleOTA did not install it (a USB flash).
Definition simpleota.h:221
One lifecycle event, valid only during the event_cb call.
Definition simpleota.h:181
simpleota_event_id_t id
What happened.
Definition simpleota.h:182
size_t bytes_total
DOWNLOAD_PROGRESS, and UPDATE_AVAILABLE (the offer's size); 0 when unknown.
Definition simpleota.h:187
const char * reason
A reason token (e.g.
Definition simpleota.h:183
size_t bytes_done
DOWNLOAD_PROGRESS only.
Definition simpleota.h:186
uint32_t build_number
The build the event is about, 0 when none.
Definition simpleota.h:185
A pinned Ed25519 public key for signed-firmware verification.
Definition simpleota.h:192
const char * pem
PEM "BEGIN PUBLIC KEY" text from the dashboard.
Definition simpleota.h:194
const char * key_id
The SimpleOTA key id (e.g.
Definition simpleota.h:193