OTA Update
HTTP(S) download, flashing, verification, reboot and rollback protection.
Data Structures
wb_iot_ota_config_t
OTA configuration.
| Field | Type | Description |
|---|---|---|
apply_mode |
wb_iot_ota_apply_mode_t |
Apply mode (default: AUTO) |
auth_token |
const char * |
Bearer token for authenticated downloads (optional) |
ca_cert |
const uint8_t * |
CA certificate for HTTPS downloads (DER, optional) |
ca_cert_len |
size_t |
Length of the CA certificate. |
http_timeout_ms |
uint32_t |
HTTP timeout for the download (default: 30000) |
mode |
wb_iot_ota_mode_t |
Download mode (default: AUTO) |
recv_buf_size |
size_t |
Receive buffer size (default: 4096) |
skip_cert_verify |
bool |
Skip certificate verification (development only!) |
wb_iot_ota_progress_t
OTA progress information.
| Field | Type | Description |
|---|---|---|
bytes_written |
size_t |
Bytes written so far. |
progress_percent |
uint8_t |
Progress in percent (0–100) |
status |
wb_iot_ota_status_t |
Current status. |
total_size |
size_t |
Total size (0 if unknown) |
Type Definitions
wb_iot_ota_handle_t
typedef struct wb_iot_ota_ctx* wb_iot_ota_handle_t
Handle of the OTA module, created by wb_iot_ota_init().
Enumerations
wb_iot_ota_apply_mode_t
Behaviour on Execute (/5/0/2).
| Enumerator | Value | Description |
|---|---|---|
WB_IOT_OTA_APPLY_AUTO |
Reboots automatically after a successful download. | |
WB_IOT_OTA_APPLY_MANUAL |
Event only, the application must trigger the reboot. |
wb_iot_ota_mode_t
Behaviour when a Package URI is received.
| Enumerator | Value | Description |
|---|---|---|
WB_IOT_OTA_MODE_AUTO |
Download starts automatically when the URI is received. | |
WB_IOT_OTA_MODE_MANUAL |
Event only, the application must start the download. |
wb_iot_ota_status_t
Detailed OTA status (beyond the LwM2M firmware state).
| Enumerator | Value | Description |
|---|---|---|
WB_IOT_OTA_STATUS_IDLE |
No OTA in progress. | |
WB_IOT_OTA_STATUS_DOWNLOADING |
HTTP download in progress. | |
WB_IOT_OTA_STATUS_DOWNLOAD_DONE |
Download complete, flash verified. | |
WB_IOT_OTA_STATUS_APPLYING |
Update is being applied (before reboot) | |
WB_IOT_OTA_STATUS_FAILED |
Failed. |
Macros
WB_IOT_OTA_CONFIG_DEFAULT()
Default OTA configuration.
#define WB_IOT_OTA_CONFIG_DEFAULT() { \
.mode = WB_IOT_OTA_MODE_AUTO, \
.apply_mode = WB_IOT_OTA_APPLY_AUTO, \
.http_timeout_ms = 30000, \
.recv_buf_size = 4096, \
.ca_cert = NULL, \
.ca_cert_len = 0, \
.skip_cert_verify = false, \
.auth_token = NULL, \
}
Functions
wb_iot_ota_abort
Aborts a running download.
esp_err_t wb_iot_ota_abort(wb_iot_ota_handle_t handle)
Parameters:
- handle (
wb_iot_ota_handle_t): OTA handle.
Returns:
ESP_OK on success.
wb_iot_ota_apply
Applies the downloaded update (sets the boot partition and reboots).
esp_err_t wb_iot_ota_apply(wb_iot_ota_handle_t handle)
Parameters:
- handle (
wb_iot_ota_handle_t): OTA handle.
Returns:
ESP_OK on success (the function does not return when rebooting).
May only be called when the status is WB_IOT_OTA_STATUS_DOWNLOAD_DONE.
wb_iot_ota_destroy
Releases all OTA resources.
esp_err_t wb_iot_ota_destroy(wb_iot_ota_handle_t handle)
Parameters:
- handle (
wb_iot_ota_handle_t): OTA handle (becomes invalid).
Returns:
ESP_OK on success.
wb_iot_ota_get_progress
Returns the current OTA progress.
esp_err_t wb_iot_ota_get_progress(wb_iot_ota_handle_t handle, wb_iot_ota_progress_t *progress)
Parameters:
- handle (
wb_iot_ota_handle_t): OTA handle. - progress (
wb_iot_ota_progress_t *): Pointer to the progress structure (filled in).
Returns:
ESP_OK on success.
wb_iot_ota_get_status
Returns the current OTA status.
wb_iot_ota_status_t wb_iot_ota_get_status(wb_iot_ota_handle_t handle)
Parameters:
- handle (
wb_iot_ota_handle_t): OTA handle.
Returns:
Current status.
wb_iot_ota_init
Initializes the OTA module.
wb_iot_ota_handle_t wb_iot_ota_init(const wb_iot_ota_config_t *config)
Parameters:
- config (
const wb_iot_ota_config_t *): OTA configuration.
Returns:
Handle, or NULL on error.
wb_iot_ota_is_pending_verify
Checks whether the running firmware has not been confirmed yet.
bool wb_iot_ota_is_pending_verify(void)
Parameters:
- **** (
void)
Returns:
true if a rollback test is running (mark_valid not called yet).
wb_iot_ota_mark_valid
Confirms a successful update after the reboot.
esp_err_t wb_iot_ota_mark_valid(void)
Parameters:
- **** (
void)
Returns:
ESP_OK if marked successfully or no rollback is necessary.
Must be called after an OTA reboot to mark the new partition as valid. Otherwise the bootloader rolls back to the previous version on the next start.
Typically: check at application start whether a rollback is pending.
wb_iot_ota_start_download
Starts the firmware download from the given URL.
esp_err_t wb_iot_ota_start_download(wb_iot_ota_handle_t handle, const char *url)
Parameters:
- handle (
wb_iot_ota_handle_t): OTA handle. - url (
const char *): Download URL (HTTP or HTTPS).
Returns:
ESP_OK if the download task was started.
Downloads the firmware via HTTP(S) and flashes it directly to the next OTA partition. Does NOT block — runs in its own FreeRTOS task.
