OTA-Update

HTTP(S)-Download, Flashen, Verifizieren, Neustart und Rollback-Schutz.

Datenstrukturen

wb_iot_ota_config_t

OTA-Konfiguration.

Feld Typ Beschreibung
apply_mode wb_iot_ota_apply_mode_t Apply-Modus (Standard: AUTO)
auth_token const char * Bearer-Token für authentifizierte Downloads (optional)
ca_cert const uint8_t * CA-Zertifikat für HTTPS-Downloads (DER, optional)
ca_cert_len size_t Länge des CA-Zertifikats.
http_timeout_ms uint32_t HTTP-Timeout für den Download (Standard: 30000)
mode wb_iot_ota_mode_t Download-Modus (Standard: AUTO)
recv_buf_size size_t Größe des Empfangspuffers (Standard: 4096)
skip_cert_verify bool Zertifikatsprüfung überspringen (nur für Entwicklung!)

wb_iot_ota_progress_t

OTA-Fortschrittsinformation.

Feld Typ Beschreibung
bytes_written size_t Bisher geschriebene Bytes.
progress_percent uint8_t Fortschritt in Prozent (0–100)
status wb_iot_ota_status_t Aktueller Status.
total_size size_t Gesamtgröße (0, wenn unbekannt)

Typdefinitionen

wb_iot_ota_handle_t

typedef struct wb_iot_ota_ctx* wb_iot_ota_handle_t

Handle des OTA-Moduls, erzeugt von wb_iot_ota_init().

Aufzählungen

wb_iot_ota_apply_mode_t

Verhalten bei Execute (/5/0/2).

Konstante Wert Beschreibung
WB_IOT_OTA_APPLY_AUTO Neustart erfolgt automatisch nach erfolgreichem Download.
WB_IOT_OTA_APPLY_MANUAL Nur Event, die Anwendung muss den Neustart selbst auslösen.

wb_iot_ota_mode_t

Verhalten beim Empfang einer Package URI.

Konstante Wert Beschreibung
WB_IOT_OTA_MODE_AUTO Download startet automatisch beim Empfang der URI.
WB_IOT_OTA_MODE_MANUAL Nur Event, die Anwendung muss den Download selbst starten.

wb_iot_ota_status_t

Detaillierter OTA-Status (über den LwM2M-Firmware-State hinaus).

Konstante Wert Beschreibung
WB_IOT_OTA_STATUS_IDLE Kein OTA aktiv.
WB_IOT_OTA_STATUS_DOWNLOADING HTTP-Download läuft.
WB_IOT_OTA_STATUS_DOWNLOAD_DONE Download abgeschlossen, Flash verifiziert.
WB_IOT_OTA_STATUS_APPLYING Update wird angewendet (vor dem Neustart)
WB_IOT_OTA_STATUS_FAILED Fehlgeschlagen.

Makros

WB_IOT_OTA_CONFIG_DEFAULT()

Standard-OTA-Konfiguration.

#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, \
}

Funktionen

wb_iot_ota_abort

Bricht einen laufenden Download ab.

esp_err_t wb_iot_ota_abort(wb_iot_ota_handle_t handle)

Parameter:

  • handle (wb_iot_ota_handle_t): OTA-Handle.

Rückgabe:

ESP_OK bei Erfolg.


wb_iot_ota_apply

Wendet das heruntergeladene Update an (setzt die Boot-Partition und startet neu).

esp_err_t wb_iot_ota_apply(wb_iot_ota_handle_t handle)

Parameter:

  • handle (wb_iot_ota_handle_t): OTA-Handle.

Rückgabe:

ESP_OK bei Erfolg (die Funktion kehrt beim Neustart nicht zurück).

Darf nur aufgerufen werden, wenn der Status WB_IOT_OTA_STATUS_DOWNLOAD_DONE ist.


wb_iot_ota_destroy

Gibt alle OTA-Ressourcen frei.

esp_err_t wb_iot_ota_destroy(wb_iot_ota_handle_t handle)

Parameter:

  • handle (wb_iot_ota_handle_t): OTA-Handle (wird ungültig).

Rückgabe:

ESP_OK bei Erfolg.


wb_iot_ota_get_progress

Gibt den aktuellen OTA-Fortschritt zurück.

esp_err_t wb_iot_ota_get_progress(wb_iot_ota_handle_t handle, wb_iot_ota_progress_t *progress)

Parameter:

  • handle (wb_iot_ota_handle_t): OTA-Handle.
  • progress (wb_iot_ota_progress_t *): Zeiger auf die Fortschrittsstruktur (wird befüllt).

Rückgabe:

ESP_OK bei Erfolg.


wb_iot_ota_get_status

Gibt den aktuellen OTA-Status zurück.

wb_iot_ota_status_t wb_iot_ota_get_status(wb_iot_ota_handle_t handle)

Parameter:

  • handle (wb_iot_ota_handle_t): OTA-Handle.

Rückgabe:

Aktueller Status.


wb_iot_ota_init

Initialisiert das OTA-Modul.

wb_iot_ota_handle_t wb_iot_ota_init(const wb_iot_ota_config_t *config)

Parameter:

  • config (const wb_iot_ota_config_t *): OTA-Konfiguration.

Rückgabe:

Handle oder NULL bei Fehler.


wb_iot_ota_is_pending_verify

Prüft, ob die laufende Firmware noch nicht bestätigt ist.

bool wb_iot_ota_is_pending_verify(void)

Parameter:

  • **** (void)

Rückgabe:

true, wenn ein Rollback-Test läuft (mark_valid noch nicht aufgerufen).


wb_iot_ota_mark_valid

Bestätigt ein erfolgreiches Update nach dem Neustart.

esp_err_t wb_iot_ota_mark_valid(void)

Parameter:

  • **** (void)

Rückgabe:

ESP_OK, wenn erfolgreich markiert oder kein Rollback nötig ist.

Muss nach einem OTA-Neustart aufgerufen werden, um die neue Partition als gültig zu markieren. Andernfalls rollt der Bootloader beim nächsten Start auf die vorherige Version zurück.

Typisch: Beim Start der Anwendung prüfen, ob ein Rollback aussteht.


wb_iot_ota_start_download

Startet den Firmware-Download von der angegebenen URL.

esp_err_t wb_iot_ota_start_download(wb_iot_ota_handle_t handle, const char *url)

Parameter:

  • handle (wb_iot_ota_handle_t): OTA-Handle.
  • url (const char *): Download-URL (HTTP oder HTTPS).

Rückgabe:

ESP_OK, wenn der Download-Task gestartet wurde.

Lädt die Firmware per HTTP(S) herunter und flasht sie direkt auf die nächste OTA-Partition. Blockiert NICHT – läuft in einem eigenen FreeRTOS-Task.