Added crash detector
This commit is contained in:
parent
34a1d7d3c3
commit
4c805fe235
@ -47,6 +47,27 @@ void tcp_cleanup() {
|
|||||||
while (tcp_tw_pcbs) tcp_abort(tcp_tw_pcbs);
|
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, ...) {
|
void writeErrorLog(const char* format, ...) {
|
||||||
File f = LittleFS.open(ERR_FILENAME, "a");
|
File f = LittleFS.open(ERR_FILENAME, "a");
|
||||||
|
|
||||||
@ -57,20 +78,23 @@ void writeErrorLog(const char* format, ...) {
|
|||||||
f = LittleFS.open(ERR_FILENAME, "a");
|
f = LittleFS.open(ERR_FILENAME, "a");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f) {
|
|
||||||
va_list arg;
|
va_list arg;
|
||||||
va_start(arg, format);
|
va_start(arg, format);
|
||||||
char buf[80];
|
char buf[120];
|
||||||
vsnprintf(&buf[0], sizeof(buf), format, arg);
|
vsnprintf(&buf[0], sizeof(buf), format, arg);
|
||||||
|
va_end(arg);
|
||||||
|
Log.errorln(&buf[0]);
|
||||||
|
|
||||||
|
if (f) {
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
f.write(&buf[0], strlen(&buf[0]));
|
f.write(&buf[0], strlen(&buf[0]));
|
||||||
#else // ESP32
|
#else // ESP32
|
||||||
f.write((unsigned char*)&buf[0], strlen(&buf[0]));
|
f.write((unsigned char*)&buf[0], strlen(&buf[0]));
|
||||||
#endif
|
#endif
|
||||||
Log.errorln(&buf[0]);
|
|
||||||
va_end(arg);
|
|
||||||
f.println();
|
f.println();
|
||||||
f.close();
|
f.close();
|
||||||
|
} else {
|
||||||
|
Log.warning(F("HELP: Failed to open error log." CR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ void tcp_cleanup();
|
|||||||
|
|
||||||
// Error logging
|
// Error logging
|
||||||
void writeErrorLog(const char* format, ...);
|
void writeErrorLog(const char* format, ...);
|
||||||
|
void checkResetReason();
|
||||||
|
|
||||||
// Sleep mode
|
// Sleep mode
|
||||||
void deepSleep(int t);
|
void deepSleep(int t);
|
||||||
|
@ -133,12 +133,9 @@ void setup() {
|
|||||||
#if LOG_LEVEL == 6 && !defined(MAIN_DISABLE_LOGGING)
|
#if LOG_LEVEL == 6 && !defined(MAIN_DISABLE_LOGGING)
|
||||||
// Add a delay so that serial is started.
|
// Add a delay so that serial is started.
|
||||||
// delay(3000);
|
// delay(3000);
|
||||||
#if defined(ESP8266)
|
|
||||||
Log.verbose(F("Main: Reset reason %s." CR), ESP.getResetInfo().c_str());
|
|
||||||
#else // defined (ESP32)
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
// Main startup
|
// Main startup
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
Log.notice(F("Main: Started setup for %s." CR),
|
Log.notice(F("Main: Started setup for %s." CR),
|
||||||
String(ESP.getChipId(), HEX).c_str());
|
String(ESP.getChipId(), HEX).c_str());
|
||||||
@ -157,6 +154,7 @@ void setup() {
|
|||||||
|
|
||||||
LOG_PERF_START("main-config-load");
|
LOG_PERF_START("main-config-load");
|
||||||
myConfig.checkFileSystem();
|
myConfig.checkFileSystem();
|
||||||
|
checkResetReason();
|
||||||
myConfig.loadFile();
|
myConfig.loadFile();
|
||||||
myWifi.init();
|
myWifi.init();
|
||||||
myAdvancedConfig.loadFile();
|
myAdvancedConfig.loadFile();
|
||||||
|
Loading…
Reference in New Issue
Block a user