Skip to content

Commit d9a51f9

Browse files
committed
Added getResetReason in human readable form
1 parent e455315 commit d9a51f9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

cores/esp8266/Esp.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,28 @@ bool EspClass::checkFlashConfig(bool needsEquals) {
329329
return false;
330330
}
331331

332+
String EspClass::getResetReason(void) {
333+
char buff[32];
334+
if (resetInfo.reason == REASON_DEFAULT_RST) { // normal startup by power on
335+
strcpy_P(buff, PSTR("Power on"));
336+
} else if (resetInfo.reason == REASON_WDT_RST) { // hardware watch dog reset
337+
strcpy_P(buff, PSTR("Hardware Watchdog"));
338+
} else if (resetInfo.reason == REASON_EXCEPTION_RST) { // exception reset, GPIO status won’t change
339+
strcpy_P(buff, PSTR("Exception"));
340+
} else if (resetInfo.reason == REASON_SOFT_WDT_RST) { // software watch dog reset, GPIO status won’t change
341+
strcpy_P(buff, PSTR("Software Watchdog"));
342+
} else if (resetInfo.reason == REASON_SOFT_RESTART) { // software restart ,system_restart , GPIO status won’t change
343+
strcpy_P(buff, PSTR("Software/System restart"));
344+
} else if (resetInfo.reason == REASON_DEEP_SLEEP_AWAKE) { // wake up from deep-sleep
345+
strcpy_P(buff, PSTR("Deep-Sleep Wake"));
346+
} else if (resetInfo.reason == REASON_EXT_SYS_RST) { // external system reset
347+
strcpy_P(buff, PSTR("External System"));
348+
} else {
349+
strcpy_P(buff, PSTR("Unknown"));
350+
}
351+
return String(buff);
352+
}
353+
332354
String EspClass::getResetInfo(void) {
333355
if(resetInfo.reason != 0) {
334356
char buff[200];

cores/esp8266/Esp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class EspClass {
131131
uint32_t getFreeSketchSpace();
132132
bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true);
133133

134+
String getResetReason();
134135
String getResetInfo();
135136
struct rst_info * getResetInfoPtr();
136137

0 commit comments

Comments
 (0)