From 07eb569cffdbb735badc974cb7600ef962cbb254 Mon Sep 17 00:00:00 2001 From: Erik Kunze Date: Sun, 16 Jun 2024 09:05:16 +0200 Subject: [PATCH] Determine the reason for the restart and send it in the status via MQTT to support the analysis of sporadic restarts. --- src/Dictionary.cpp | 1 + src/Dictionary.h | 1 + src/DisplayManager.cpp | 4 +++- src/reset.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/reset.h | 8 ++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/reset.cpp create mode 100644 src/reset.h diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index e48bce0e..e0a39e4e 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp @@ -159,3 +159,4 @@ const char MessagesKey[] PROGMEM = {"messages"}; const char VersionKey[] PROGMEM = {"version"}; const char RamKey[] PROGMEM = {"ram"}; const char IpAddrKey[] PROGMEM = {"ip_address"}; +const char ResetReasonKey[] PROGMEM = {"reset_reason"}; diff --git a/src/Dictionary.h b/src/Dictionary.h index e1b045f3..6a799e40 100644 --- a/src/Dictionary.h +++ b/src/Dictionary.h @@ -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 diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index 34c28ba0..6068a6ed 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -22,6 +22,7 @@ #include #include "base64.hpp" #include "GameManager.h" +#include "reset.h" unsigned long lastArtnetStatusTime = 0; const int numberOfChannels = 256 * 3; @@ -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; @@ -2776,4 +2778,4 @@ void DisplayManager_::setCursor(int16_t x, int16_t y) void DisplayManager_::setTextColor(uint32_t color) { textColor = color; -} \ No newline at end of file +} diff --git a/src/reset.cpp b/src/reset.cpp new file mode 100644 index 00000000..16fdc1fb --- /dev/null +++ b/src/reset.cpp @@ -0,0 +1,40 @@ +#include +#include +#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 +} + diff --git a/src/reset.h b/src/reset.h new file mode 100644 index 00000000..1a809bec --- /dev/null +++ b/src/reset.h @@ -0,0 +1,8 @@ +#ifndef __RESET_H +#define __RESET_H + +#include + +String ESP_getResetReason(void); + +#endif // __RESET_H