Skip to content

Save exception details and stack trace to the SPIFFS everytime the ESP8266 crashes

License

Notifications You must be signed in to change notification settings

brainelectronics/EspSaveCrashSpiffs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EspSaveCrashSpiffs

Save exception details and stack trace to SPIFFS everytime the ESP8266 crashes. Implement it in your sketch in two simple steps.

Overview

EspSaveCrashSpiffs is another 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.

This library is inspired by the EspSaveCrash library written by krzychb.

You will implement it in your sketch in two simple steps:

  1. Include the library
#include "EspSaveCrashSpiffs.h"
  1. Declare object
EspSaveCrashSpiffs SaveCrashSpiffs(0);

That's it.

To print out the latest crash log to Serial use this:

// allocate some space for the latest log filename
char* _lastCrashFileName;
_lastCrashFileName = (char*)calloc(255, sizeof(char));

// get the last filename
SaveCrashSpiffs.getLastLogFileName(_lastCrashFileName);

Serial.printf("Name of last log file: '%s'\n", _lastCrashFileName);

Serial.println("--- BEGIN of crash file ---");
SaveCrashSpiffs.print(_lastCrashFileName);
Serial.println("--- END of crash file ---");

// free the allocated space
free(_lastCrashFileName);

Example serial output might be something like this:

Name of last log file: '/crashLog-5.log'
--- BEGIN of crash file ---
Crashed at 33535 ms
Restart reason: 2
Exception cause: 28
epc1=0x4020161a epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
>>>stack>>>
3fffff90: 00000a65 00000000 00000001 40202cfd
3fffffa0: 3fffdad0 00000000 3ffee958 40202d8c
3fffffb0: feefeffe feefeffe 3ffe8504 40100459
<<<stack<<<

--- END of crash file ---

The browser output looks like that: alt text

To delete existing crash files from the flash refer to the deleteSomeFile() function in the SimpleCrashSpiffs example.

Check the examples folder for sample implementation of this library and tracking down where the program crash happened. Also an example to show how to access to latest saved information remotely with a web browser.

Compatibility

Functionality

  • 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 and depc
    • 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 file to default file and renames this to the next logical name after a reboot. Small files avoid reboots due to buffer overflow or out of RAM stuff.

Examples

Library comes with example sketches that let you trigger some exceptions and see how to visualize saved data.

Tested With

Arduino Core

Programming Environment

Installation

  • Arduino IDE - use Library Manager in Arduino IDE and search for EspSaveCrash.
  • Visual Micro - installation procedure is the same as for Arduino IDE above.

Contribute

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.

Author

brainelectronics

Credits

  • Big thanks to krzychb who inspired me to extend it's great EspSaveCrash library to use now the SPIFFS
  • Preparation of this library has been inspired by issue #1152 in esp8266 / Arduino repository.

License

GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999

About

Save exception details and stack trace to the SPIFFS everytime the ESP8266 crashes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages