How to detect the first boot after OTA update

Posts: 1
Joined: Tue Sep 04, 2018 2:31 pm

How to detect the first boot after OTA update

Postby Hr.Mitrev » Thu Oct 29, 2020 2:03 pm


I'm using OTA with esp32 and recently I decided to implement failsafe in case of me as a programmer mess up the code and after update the new firmware doesn't connect properly to my server and as a cosequence I cannot do any more updates.

I can easily store something in nvs(or rtc noinit memory) before starting OTA and delete it after successful connection to the server(and use esp_ota_mark_app_valid_cancel_rollback), but I was wondering if there's a cleverer way to detect first boot after update?

Extra points if I can do it with minimal initialization of peripherals as early after boot as possible.

Thanks :)

Posts: 18
Joined: Tue Oct 02, 2018 7:11 am

Re: How to detect the first boot after OTA update

Postby gecko242 » Thu Oct 29, 2020 4:51 pm

Yup, dead easy:

Firstly, enable the below config option. This means that, if you do not explicitly mark the new img as OK, it will automatically roll back upon the next boot.


Then check to see if your img is pending verification:

Code: Select all

esp_ota_img_states_t imgState;
esp_ota_get_state_partition(esp_ota_get_running_partition(), &imgState);

if(imgState == ESP_OTA_IMG_PENDING_VERIFY) // we need to run self tests, and mark this update as OK
	flag_runSelfTest = true;
	ESP_LOGI(TAG, "New img detected. Run self test and confirm OK");
Once you have performed your self tests, you can mark the img as good, canceling the pending rollback:

Code: Select all


Who is online

Users browsing this forum: Google [Bot] and 32 guests