Added crash detector

This commit is contained in:
Magnus Persson 2022-08-05 18:17:10 +02:00
parent 34a1d7d3c3
commit 4c805fe235
3 changed files with 33 additions and 10 deletions

View File

@ -47,6 +47,27 @@ void tcp_cleanup() {
while (tcp_tw_pcbs) tcp_abort(tcp_tw_pcbs);
}
void checkResetReason() {
#if defined(ESP8266)
rst_info* _rinfo;
_rinfo = ESP.getResetInfoPtr();
Log.notice(F("HELP: Last reset cause %d" CR), _rinfo->exccause);
if (_rinfo->exccause > 0) {
char s[120];
snprintf(&s[0], sizeof(s),
"HELP: Exception (%d) reason=%d epc1=0x%08x epc2=0x%08x "
"epc3=0x%08x execvaddr=0x%08x depc=0x%08x",
_rinfo->exccause, _rinfo->reason, _rinfo->epc1, _rinfo->epc2,
_rinfo->epc3, _rinfo->excvaddr, _rinfo->depc);
writeErrorLog(&s[0]);
}
#else // defined (ESP32)
#warning "Todo: Handle reset reasons on ESP32"
#endif
}
void writeErrorLog(const char* format, ...) {
File f = LittleFS.open(ERR_FILENAME, "a");
@ -57,20 +78,23 @@ void writeErrorLog(const char* format, ...) {
f = LittleFS.open(ERR_FILENAME, "a");
}
va_list arg;
va_start(arg, format);
char buf[120];
vsnprintf(&buf[0], sizeof(buf), format, arg);
va_end(arg);
Log.errorln(&buf[0]);
if (f) {
va_list arg;
va_start(arg, format);
char buf[80];
vsnprintf(&buf[0], sizeof(buf), format, arg);
#if defined(ESP8266)
f.write(&buf[0], strlen(&buf[0]));
#else // ESP32
f.write((unsigned char*)&buf[0], strlen(&buf[0]));
#endif
Log.errorln(&buf[0]);
va_end(arg);
f.println();
f.close();
} else {
Log.warning(F("HELP: Failed to open error log." CR));
}
}

View File

@ -38,6 +38,7 @@ void tcp_cleanup();
// Error logging
void writeErrorLog(const char* format, ...);
void checkResetReason();
// Sleep mode
void deepSleep(int t);

View File

@ -133,12 +133,9 @@ void setup() {
#if LOG_LEVEL == 6 && !defined(MAIN_DISABLE_LOGGING)
// Add a delay so that serial is started.
// delay(3000);
#if defined(ESP8266)
Log.verbose(F("Main: Reset reason %s." CR), ESP.getResetInfo().c_str());
#else // defined (ESP32)
#endif
#endif
// Main startup
#if defined(ESP8266)
Log.notice(F("Main: Started setup for %s." CR),
String(ESP.getChipId(), HEX).c_str());
@ -157,6 +154,7 @@ void setup() {
LOG_PERF_START("main-config-load");
myConfig.checkFileSystem();
checkResetReason();
myConfig.loadFile();
myWifi.init();
myAdvancedConfig.loadFile();