Skip to content

Commit aa1cb1f

Browse files
authored
Merge pull request #2765 from fizzyfuzzle/ESP32-Reset-Reason
Add ESP32 Reset Reason to existing pwrmgt.bootreason cli command
2 parents 6a63dfc + e7db7c5 commit aa1cb1f

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/helpers/CommonCLI.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,13 +953,9 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep
953953
strcpy(reply, "ERROR: Power management not supported");
954954
#endif
955955
} else if (memcmp(config, "pwrmgt.bootreason", 17) == 0) {
956-
#ifdef NRF52_POWER_MANAGEMENT
957956
sprintf(reply, "> Reset: %s; Shutdown: %s",
958957
_board->getResetReasonString(_board->getResetReason()),
959958
_board->getShutdownReasonString(_board->getShutdownReason()));
960-
#else
961-
strcpy(reply, "ERROR: Power management not supported");
962-
#endif
963959
} else if (memcmp(config, "pwrmgt.bootmv", 13) == 0) {
964960
#ifdef NRF52_POWER_MANAGEMENT
965961
sprintf(reply, "> %u mV", _board->getBootVoltage());

src/helpers/ESP32Board.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,42 @@ class ESP32Board : public mesh::MainBoard {
155155
void setInhibitSleep(bool inhibit) {
156156
inhibit_sleep = inhibit;
157157
}
158+
159+
uint32_t getResetReason() const override {
160+
return esp_reset_reason();
161+
}
162+
163+
// https://docs.espressif.com/projects/esp-idf/en/v4.4.7/esp32/api-reference/system/system.html
164+
const char* getResetReasonString(uint32_t reason) {
165+
switch (reason) {
166+
case ESP_RST_UNKNOWN:
167+
return "Unknown or first boot";
168+
case ESP_RST_POWERON:
169+
return "Power-on reset";
170+
case ESP_RST_EXT:
171+
return "External reset";
172+
case ESP_RST_SW:
173+
return "Software reset";
174+
case ESP_RST_PANIC:
175+
return "Panic / exception reset";
176+
case ESP_RST_INT_WDT:
177+
return "Interrupt watchdog reset";
178+
case ESP_RST_TASK_WDT:
179+
return "Task watchdog reset";
180+
case ESP_RST_WDT:
181+
return "Other watchdog reset";
182+
case ESP_RST_DEEPSLEEP:
183+
return "Wake from deep sleep";
184+
case ESP_RST_BROWNOUT:
185+
return "Brownout (low voltage)";
186+
case ESP_RST_SDIO:
187+
return "SDIO reset";
188+
default:
189+
static char buf[40];
190+
snprintf(buf, sizeof(buf), "Unknown reset reason (%d)", reason);
191+
return buf;
192+
}
193+
}
158194
};
159195

160196
class ESP32RTCClock : public mesh::RTCClock {

0 commit comments

Comments
 (0)