Skip to content

Commit

Permalink
Determine the reason for the restart and send it
Browse files Browse the repository at this point in the history
in the status via MQTT to support the analysis of
sporadic restarts.
  • Loading branch information
eku committed Jun 16, 2024
1 parent 574e0b8 commit 779cc1a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ const char MessagesKey[] PROGMEM = {"messages"};
const char VersionKey[] PROGMEM = {"version"};
const char RamKey[] PROGMEM = {"ram"};
const char IpAddrKey[] PROGMEM = {"ip_address"};
const char ResetReasonRawKey[] PROGMEM = {"reset_reason_raw"};
const char ResetReasonKey[] PROGMEM = {"reset_reason"};
1 change: 1 addition & 0 deletions src/Dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,5 @@ extern const char MessagesKey[];
extern const char VersionKey[];
extern const char RamKey[];
extern const char IpAddrKey[];
extern const char ResetReasonKey[];
#endif
4 changes: 3 additions & 1 deletion src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <HTTPClient.h>
#include "base64.hpp"
#include "GameManager.h"
#include "reset.h"

unsigned long lastArtnetStatusTime = 0;
const int numberOfChannels = 256 * 3;
Expand Down Expand Up @@ -1623,6 +1624,7 @@ String DisplayManager_::getStats()
doc[F("uid")] = uniqueID;
doc[F("matrix")] = !MATRIX_OFF;
doc[IpAddrKey] = WiFi.localIP();
doc[ResetReasonKey] = ESP_getResetReason();
String jsonString;
serializeJson(doc, jsonString);
return jsonString;
Expand Down Expand Up @@ -2776,4 +2778,4 @@ void DisplayManager_::setCursor(int16_t x, int16_t y)
void DisplayManager_::setTextColor(uint32_t color)
{
textColor = color;
}
}
40 changes: 40 additions & 0 deletions src/reset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <Arduino.h>
#include <rom/rtc.h>
#include "reset.h"

String ESP32GetResetReason(uint32_t cpu_no) {
// tools\sdk\include\esp32\rom\rtc.h
// tools\sdk\esp32\include\esp_rom\include\esp32c3\rom\rtc.h
// tools\sdk\esp32\include\esp_rom\include\esp32s2\rom\rtc.h
switch (rtc_get_reset_reason(cpu_no)) { // ESP32 ESP32-S / ESP32-C
case 1 : return F("Vbat power on reset"); // 1 POWERON_RESET POWERON_RESET
case 3 : return F("Software reset digital core"); // 3 SW_RESET RTC_SW_SYS_RESET
case 4 : return F("Legacy watch dog reset digital core"); // 4 OWDT_RESET -
case 5 : return F("Deep Sleep reset digital core"); // 5 DEEPSLEEP_RESET DEEPSLEEP_RESET
case 6 : return F("Reset by SLC module, reset digital core"); // 6 SDIO_RESET
case 7 : return F("Timer Group0 Watch dog reset digital core"); // 7 TG0WDT_SYS_RESET
case 8 : return F("Timer Group1 Watch dog reset digital core"); // 8 TG1WDT_SYS_RESET
case 9 : return F("RTC Watch dog Reset digital core"); // 9 RTCWDT_SYS_RESET
case 10 : return F("Instrusion tested to reset CPU"); // 10 INTRUSION_RESET
case 11 : return F("Time Group0 reset CPU"); // 11 TGWDT_CPU_RESET TG0WDT_CPU_RESET
case 12 : return F("Software reset CPU"); // 12 SW_CPU_RESET RTC_SW_CPU_RESET
case 13 : return F("RTC Watch dog Reset CPU"); // 13 RTCWDT_CPU_RESET
case 14 : return F("or APP CPU, reseted by PRO CPU"); // 14 EXT_CPU_RESET -
case 15 : return F("Reset when the vdd voltage is not stable"); // 15 RTCWDT_BROWN_OUT_RESET
case 16 : return F("RTC Watch dog reset digital core and rtc module"); // 16 RTCWDT_RTC_RESET
case 17 : return F("Time Group1 reset CPU"); // 17 - TG1WDT_CPU_RESET
case 18 : return F("Super watchdog reset digital core and rtc module"); // 18 - SUPER_WDT_RESET
case 19 : return F("Glitch reset digital core and rtc module"); // 19 - GLITCH_RTC_RESET
case 20 : return F("Efuse reset digital core"); // 20 EFUSE_RESET
case 21 : return F("Usb uart reset digital core"); // 21 USB_UART_CHIP_RESET
case 22 : return F("Usb jtag reset digital core"); // 22 USB_JTAG_CHIP_RESET
case 23 : return F("Power glitch reset digital core and rtc module"); // 23 POWER_GLITCH_RESET
}

return F("No meaning"); // 0 and undefined
}

String ESP_getResetReason(void) {
return ESP32GetResetReason(0); // CPU 0
}

8 changes: 8 additions & 0 deletions src/reset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __RESET_H
#define __RESET_H

#include <Arduino.h>

String ESP_getResetReason(void);

#endif // __RESET_H

0 comments on commit 779cc1a

Please sign in to comment.