How to detect ESP restart from upgrade

Jimis1
Posts: 35
Joined: Wed May 03, 2023 6:20 am

How to detect ESP restart from upgrade

Postby Jimis1 » Tue Mar 05, 2024 7:32 am

Hi

I'm trying to check whether the ESP has reset from an upgrade (USB or OTA) to reset my "reset_counter" variable which is stored in flash.

I tried to detect that from the response from the function nvs_get(). If I get a "value not initialized" then it means I had a code upgrade and I should reset the "reset_counter" variable. But it seems that after I upgrade my code this variable is still initialized !

Can someone help ?
Screenshot_2.jpg
Screenshot_2.jpg (35.54 KiB) Viewed 831 times

MicroController
Posts: 1221
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to detect ESP restart from upgrade

Postby MicroController » Tue Mar 05, 2024 8:05 am

How about storing a "firmware version" in NVS?
If versionFromNvs != thisAppsVersion then there was an 'upgrade'.

Jimis1
Posts: 35
Joined: Wed May 03, 2023 6:20 am

Re: How to detect ESP restart from upgrade

Postby Jimis1 » Tue Mar 05, 2024 8:45 am

Yes I have thought of that, but I was looking for something non-user dependent (during testing you don't change versions all the time).

If there is no other way I will do it this way, I just thought that it should work this way

For example ATMEL μCs have a register that defines the reason of a reset (WD,brown-out,external etc)

MicroController
Posts: 1221
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to detect ESP restart from upgrade

Postby MicroController » Tue Mar 05, 2024 10:17 am

Jimis1 wrote:
Tue Mar 05, 2024 8:45 am
Yes I have thought of that, but I was looking for something non-user dependent (during testing you don't change versions all the time).
esp_app_get_description() could help.
For example ATMEL μCs have a register that defines the reason of a reset (WD,brown-out,external etc)
-> https://docs.espressif.com/projects/esp ... set-reason
But that's probably of no use in your case.

mikemoy
Posts: 606
Joined: Fri Jan 12, 2018 9:10 pm

Re: How to detect ESP restart from upgrade

Postby mikemoy » Fri Mar 08, 2024 10:47 pm

Yes I have thought of that, but I was looking for something non-user dependent (during testing you don't change versions all the time).
What about running a checksum on the flash, and comparing that value to the last value saved.

mikemoy
Posts: 606
Joined: Fri Jan 12, 2018 9:10 pm

Re: How to detect ESP restart from upgrade

Postby mikemoy » Fri Mar 08, 2024 10:48 pm

Yes I have thought of that, but I was looking for something non-user dependent (during testing you don't change versions all the time).
What about running a checksum on the flash, and comparing that value to the last value saved.

mikemoy
Posts: 606
Joined: Fri Jan 12, 2018 9:10 pm

Re: How to detect ESP restart from upgrade

Postby mikemoy » Fri Mar 08, 2024 10:48 pm

Yes I have thought of that, but I was looking for something non-user dependent (during testing you don't change versions all the time).
What about running a checksum on the flash, and comparing that value to the last value saved.

Jimis1
Posts: 35
Joined: Wed May 03, 2023 6:20 am

Re: How to detect ESP restart from upgrade

Postby Jimis1 » Sun Mar 10, 2024 12:14 pm

Thanks all ! I will have to implement one of the above :)

Who is online

Users browsing this forum: No registered users and 168 guests