Capturing an exception crashing the app

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Capturing an exception crashing the app

Postby fly135 » Wed Apr 25, 2018 3:41 pm

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

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Capturing an exception crashing the app

Postby kolban » Wed Apr 25, 2018 4:05 pm

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:

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;
   }
}
The crash counter can be in NVS for persistence between boots.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Capturing an exception crashing the app

Postby fly135 » Wed Apr 25, 2018 4:17 pm

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.

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