I'm using OTA to update the firmware and would like to be able to go back to the factory partition should I download a bad update or anything goes wrong that causes a continuous exception/reboot cycle. If I could capture the exception and "if" the system is still stable enough to execute a command to erase the OTADATA partition then reboot back to the stable factory partition. Anybody got an idea about how to do this? Seems like every time I have a question somebody posts a link to the docs that I missed. I searched the docs for exception but nothing came up of obvious use.
John A
Capturing an exception crashing the app
Re: Capturing an exception crashing the app
Howdy John,
I think we want to break apart the puzzle into multiple piece. The first piece would be detection that "something wrong" and the second would be "repair".
To detect that something is wrong, we might have to invent an algorithm.
Lets assume that you always get control in app_main in order to still have some semblance of control. An algorithm might be:
The crash counter can be in NVS for persistence between boots.
I think we want to break apart the puzzle into multiple piece. The first piece would be detection that "something wrong" and the second would be "repair".
To detect that something is wrong, we might have to invent an algorithm.
Lets assume that you always get control in app_main in order to still have some semblance of control. An algorithm might be:
Code: Select all
main() {
if (reason for reboot is previous crash) {
increment crash counter;
if crash counter > 10 {
Perform repair;
reboot
}
} else {
set crash counter to 0;
}
}
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: Capturing an exception crashing the app
Seems like a chicken and egg problem. "reason for reboot is previous crash" is what I'm trying to get from capturing the exception.
This could work... but I'd still like to capture that exception if possible.
This could work... but I'd still like to capture that exception if possible.
Code: Select all
main()
{
if (nvs says "reboot")
set crash counter to 0;
else if ( nvs says "run" )
{
increment crash counter;
if crash counter > 10 {
Perform repair;
reboot
}
}
else
{
printf("first run nvs is not inited")
set crash count to zero
}
nvs write "run"
... do stuff
}
void normal_shutdown()
{
nvs write "reboot"
reboot
}
Who is online
Users browsing this forum: Majestic-12 [Bot] and 94 guests