SimpleOTA client v1.0.1
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 0
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)
106
121
140
170typedef struct {
172 const char *reason;
174 uint32_t build_number;
175 size_t bytes_done;
176 size_t bytes_total;
179
181typedef struct {
182 const char *key_id;
183 const char *pem;
185
190typedef struct {
191 const char *token;
192 const char *base_url;
194 const char *device_id;
195 const char *chip_family;
197 const char *board_id;
198 const char *hardware_revision;
199 const char *partition_profile;
200 const char *channel;
201 const char *labels_json;
207 const char *version_label;
209 uint32_t image_build;
244 bool (*is_connected)(void *user_ctx);
249 void (*event_cb)(const simpleota_event_t *event, void *user_ctx);
250 void *user_ctx;
260 const char *cert_pem;
261 esp_err_t (*crt_bundle_attach)(void *conf);
264
285esp_err_t simpleota_init(const simpleota_config_t *config);
286
297esp_err_t simpleota_start(void);
298
306esp_err_t simpleota_stop(void);
307
314esp_err_t simpleota_check_now(void);
315
335esp_err_t simpleota_check(bool *update_available);
336
347
359esp_err_t simpleota_set_server_url(const char *url);
360
366
378esp_err_t simpleota_confirm(void);
379
393
396
402
411esp_err_t simpleota_deinit(void);
412
413#ifdef __cplusplus
414}
415#endif
416
417#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_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:108
@ SIMPLEOTA_FLASH_FAIL
Network, URL, flash or state write failure.
Definition simpleota.h:111
@ SIMPLEOTA_DOWNGRADE
The offered build is not above the running one; refused (anti-rollback).
Definition simpleota.h:118
@ SIMPLEOTA_UNCONFIRMED
The running image is on trial: confirm it, then apply again.
Definition simpleota.h:116
@ SIMPLEOTA_REBOOT_PENDING
A flashed update waits for simpleota_reboot_for_update().
Definition simpleota.h:114
@ SIMPLEOTA_CHECKSUM_FAIL
The download did not match its SHA-256.
Definition simpleota.h:110
@ SIMPLEOTA_NO_OFFER
No offer from a successful simpleota_check().
Definition simpleota.h:112
@ SIMPLEOTA_SIGNATURE_FAIL
Required signature missing or wrong.
Definition simpleota.h:113
@ SIMPLEOTA_OK
Flashed and verified; the reboot is next.
Definition simpleota.h:109
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:123
@ SIMPLEOTA_EVENT_DOWNLOAD_PROGRESS
bytes_done / bytes_total advanced.
Definition simpleota.h:128
@ SIMPLEOTA_EVENT_ROLLING_BACK
The trial failed; the previous image starts next.
Definition simpleota.h:137
@ SIMPLEOTA_EVENT_TRIAL_BOOT
Running an unconfirmed (trial) image.
Definition simpleota.h:134
@ SIMPLEOTA_EVENT_CONFIRMED
The trial image's confirmed report was delivered.
Definition simpleota.h:135
@ SIMPLEOTA_EVENT_BEFORE_REBOOT
Flashed + verified.
Definition simpleota.h:130
@ SIMPLEOTA_EVENT_UPDATE_FAILED
Update aborted; reason carries the token.
Definition simpleota.h:129
@ SIMPLEOTA_EVENT_UPDATE_AVAILABLE
An update was offered.
Definition simpleota.h:126
@ SIMPLEOTA_EVENT_CHECK_DONE
A check completed; no update offered.
Definition simpleota.h:124
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:190
const char * hardware_revision
Board revision.
Definition simpleota.h:198
const char * base_url
Default: "https://simpleota.com".
Definition simpleota.h:192
uint32_t check_interval_s
Seconds between checks.
Definition simpleota.h:215
uint32_t initial_delay_ms
Delay before the first check after start().
Definition simpleota.h:221
const char * version_label
Default: the label stored with the update that installed this image.
Definition simpleota.h:207
const simpleota_signing_key_t * signing_keys
Pinned public keys for signed firmware, at most 2.
Definition simpleota.h:237
const char * board_id
Board model.
Definition simpleota.h:197
const char * cert_pem
TLS trust, always verified.
Definition simpleota.h:260
const char * channel
Release channel.
Definition simpleota.h:200
uint8_t nvs_schema_version
The data schema this firmware expects.
Definition simpleota.h:214
simpleota_security_t security_mode
Default: SIMPLEOTA_SECURITY_NONE.
Definition simpleota.h:205
uint32_t confirm_timeout_s
Seconds a trial has to confirm.
Definition simpleota.h:224
const char * labels_json
Reserved: pre-formed JSON object sent verbatim on check-ins, but not yet consumed by the platform.
Definition simpleota.h:201
const char * chip_family
Default: CONFIG_IDF_TARGET ("esp32", "esp32s3", ...), the chip the firmware is built for.
Definition simpleota.h:195
const char * device_id
Default: Wi-Fi STA MAC "aa:bb:cc:dd:ee:ff".
Definition simpleota.h:194
bool manual_confirm
Managed mode: true = the app calls simpleota_confirm(); false = the first successful check-in confirm...
Definition simpleota.h:226
uint8_t num_signing_keys
Entries in signing_keys.
Definition simpleota.h:238
const char * token
Required.
Definition simpleota.h:191
void * user_ctx
Passed to is_connected and event_cb.
Definition simpleota.h:250
bool disable_auto_reboot
true: the app calls simpleota_reboot_for_update().
Definition simpleota.h:230
const char * partition_profile
Partition layout name.
Definition simpleota.h:199
uint32_t image_build
This image's build number, reported when SimpleOTA did not install it (a USB flash).
Definition simpleota.h:209
One lifecycle event, valid only during the event_cb call.
Definition simpleota.h:170
simpleota_event_id_t id
What happened.
Definition simpleota.h:171
size_t bytes_total
DOWNLOAD_PROGRESS, and UPDATE_AVAILABLE (the offer's size); 0 when unknown.
Definition simpleota.h:176
const char * reason
A reason token (e.g.
Definition simpleota.h:172
size_t bytes_done
DOWNLOAD_PROGRESS only.
Definition simpleota.h:175
uint32_t build_number
The build the event is about, 0 when none.
Definition simpleota.h:174
A pinned Ed25519 public key for signed-firmware verification.
Definition simpleota.h:181
const char * pem
PEM "BEGIN PUBLIC KEY" text from the dashboard.
Definition simpleota.h:183
const char * key_id
The SimpleOTA key id (e.g.
Definition simpleota.h:182