Save exception details and stack trace anytime and anywhere the ESP8266 crashes. Implement it in your sketch in two simple steps.
Do you face random crashes of ESP8266? Do you have difficulty to capture diagnostic information because module is in remote location? Or maybe module crashes after several hours of operation and it is inconvenient to keep serial monitor open until it fails?
EspSaveCrash is a handy little library that will keep automatically catching and saving crash information to ESP8266 module's flash in case it fails due to exception or software WDT. You will then be able to analyze the crash log and decode the stack trace using ESP Exception Decoder.
You will implement it in your sketch in two simple steps:
- Include the library
#include "EspSaveCrash.h"
- Declare object
EspSaveCrash SaveCrash;
- Print out saved crash details
SaveCrash.print();
To clear existing crash history from the flash use SaveCrash.clear()
.
Check section Quick Start for sample implementation of this library and tracking down where the program crash happened. More code samples are available in section Examples, that also covers access to saved information remotely with a web browser.
Quick Start | Code Examples |
- Library works with any ESP8266 module programmed using esp8266 / Arduino core.
- Registers callback to automatically capture and save crash details
- Captures several crashes to save them to ESP8266 module's flash
- Captures exceptions and software WDT restarts (not hardware WDT)
- The following information is saved:
- Time of crash using the ESP's milliseconds counter
- Reason of restart - see rst cause
- Exception cause - see EXCCAUSE
epc1
,epc2
,epc3
,excvaddr
anddepc
- Stack trace in format you can analyze with ESP Exception Decoder
- Automatically arms itself to operate after each restart or power up of module
- Saves crash details within defined flash space and then stops
Example output of SaveCrash.print()
:
Library comes with example sketches that let you trigger some exceptions and see how to visualize saved data.
Please check separate section how to use example sketches and what particular functionality they provide.
- Esp8266 / Arduino core 2.3.0 for Arduino IDE and Visual Micro
- framework-arduinoespressif version 13 for PlatformIO
- Arduino IDE 1.6.9 portable version running on Windows 7 x64
- PlatformIO IDE 1.3.0 CLI 2.11.0 running on Windows 7 x64
- Visual Micro 1606.17.10 with Visual Studio Community 2015 running on Windows 7 x64
- Arduino IDE - use Library Manager in Arduino IDE and search for EspSaveCrash.
- PlatformIO IDE - use PlatformIO's Library Manager. In particular execute
pio lib install 376
. - Visual Micro - installation procedure is the same as for Arduino IDE above.
Feel free to contribute to the project in any way you like!
If you find any issues with code or descriptions please report them using Issues tab above.
krzychb
- Preparation of this library has been inspired by issue #1152 in esp8266 / Arduino repository.
- Development was possible thanks to Ivan Grokhotkov, who clarified how to register a crash callback and suggested to save crash information on flash.
- Actual implementation of library has been done thanks to djoele who provided first working code and suggested to convert it into general functionality.
- Thanks to contribution by Juan L. Pérez Díez the library accepts offset and size parameters passed into the constructor.
- With kind contribution by brainelectronics the crash log can be stored to char buffer for more convenient use with a web server.
GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999