Home / Learn Chip Programming / OTA Updates: Safe Remote Firmware Update
OTA Updates: Safe Remote Firmware Update
Update devices in the field over Wi-Fi without cables.
Theory in plain words
What it is
OTA writes a new firmware image into the inactive app partition, verifies it, then switches the boot partition. If the new image fails, rollback returns to the old one.
Why we use it
A product without OTA cannot fix bugs after sale. A bad OTA that bricks devices is a disaster, so safety matters.
How it works
Host the .bin over HTTPS, download with esp_https_ota, verify the signature and version, set the boot partition, reboot, mark the new app valid after a self-test, otherwise roll back.
Where it is used
- Smart home devices
- Remote sensors
- Fleet updates
OTA state machine
Rollback is the safety net. Enable CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE and call esp_ota_mark_app_valid_cancel_rollback() only after your self-test passes.
esp_http_client_config_t http = { .url = "https://example.com/fw/v1.1.bin", .cert_pem = server_cert_pem, .timeout_ms = 10000 };
esp_https_ota_config_t ota = { .http_config = &http };
if (esp_https_ota(&ota) == ESP_OK) esp_restart();
// after reboot, in app_main when everything works:
esp_ota_mark_app_valid_cancel_rollback();- Always use HTTPS and verify the server certificate.
- Enable secure boot signing so only your firmware can run.
- Check a version number so you never "update" to an older image.
- Keep battery and signal checks: never start OTA below 30 percent battery.
Quick quiz
1. What protects against a bad update?
The bootloader returns to the old app.
2. When mark the new app valid?
Only confirmed good images stay.
Common questions
What protects against a bad update?
Rollback to the previous partition. The bootloader returns to the old app.
When mark the new app valid?
After a successful self-test. Only confirmed good images stay.