[Crashinfo] Decode intended reboot reason

This commit is contained in:
TD-er
2020-10-21 16:22:25 +02:00
parent 88517aa0a0
commit 2e7dccea5a
17 changed files with 70 additions and 27 deletions
+1 -1
View File
@@ -261,7 +261,7 @@ void setup()
}
log += RTC.bootCounter;
log += F(" Last Task: ");
log += F(" Last Action before Reboot: ");
log += ESPEasy_Scheduler::decodeSchedulerId(lastMixedSchedulerId_beforereboot);
log += F(" Last systime: ");
log += RTC.lastSysTime;
+1 -1
View File
@@ -50,7 +50,7 @@ String getLabel(LabelType::Enum label) {
case LabelType::BOOT_TYPE: return F("Last Boot Cause");
case LabelType::BOOT_COUNT: return F("Boot Count");
case LabelType::RESET_REASON: return F("Reset Reason");
case LabelType::LAST_TASK_BEFORE_REBOOT: return F("Last Task");
case LabelType::LAST_TASK_BEFORE_REBOOT: return F("Last Action before Reboot");
case LabelType::SW_WD_COUNT: return F("SW WD count");
+1 -1
View File
@@ -63,7 +63,7 @@ void handle_settingsarchive() {
}
} else if (web_server.hasArg(F("reboot"))) {
showOptions = false;
reboot();
reboot(ESPEasy_Scheduler::IntendedRebootReason_e::RestoreSettings);
}
if (showOptions) {
+1 -1
View File
@@ -298,7 +298,7 @@ bool executeInternalCommand(const char *cmd, struct EventStruct *event, const ch
COMMAND_CASE_A("reboot", Command_System_Reboot, 0); // System.h
COMMAND_CASE_R("reset", Command_Settings_Reset, 0); // Settings.h
COMMAND_CASE_A("resetflashwritecounter", Command_RTC_resetFlashWriteCounter, 0); // RTC.h
COMMAND_CASE_A( "restart", Command_System_Restart, 0); // System.h
COMMAND_CASE_A( "restart", Command_System_Reboot, 0); // System.h
COMMAND_CASE_A( "rules", Command_Rules_UseRules, 1); // Rule.h
break;
}
+1 -1
View File
@@ -92,6 +92,6 @@ String Command_Settings_Print(struct EventStruct *event, const char* Line)
String Command_Settings_Reset(struct EventStruct *event, const char* Line)
{
ResetFactory();
reboot();
reboot(ESPEasy_Scheduler::IntendedRebootReason_e::ResetFactoryCommand);
return return_command_success();
}
+2 -6
View File
@@ -9,6 +9,7 @@
#include "../Helpers/DeepSleep.h"
#include "../Helpers/Misc.h"
#include "../Helpers/Scheduler.h"
String Command_System_NoSleep(struct EventStruct *event, const char* Line)
{
@@ -31,12 +32,7 @@ String Command_System_Reboot(struct EventStruct *event, const char* Line)
pinMode(0, INPUT);
pinMode(2, INPUT);
pinMode(15, INPUT);
reboot();
reboot(ESPEasy_Scheduler::IntendedRebootReason_e::CommandReboot);
return return_command_success();
}
String Command_System_Restart(struct EventStruct *event, const char* Line)
{
ESP.restart();
return return_command_success();
}
-1
View File
@@ -6,6 +6,5 @@ class String;
String Command_System_NoSleep(struct EventStruct *event, const char* Line);
String Command_System_deepSleep(struct EventStruct *event, const char* Line);
String Command_System_Reboot(struct EventStruct *event, const char* Line);
String Command_System_Restart(struct EventStruct *event, const char* Line);
#endif // COMMAND_SYSTEM_H
+1 -1
View File
@@ -113,7 +113,7 @@ void deepSleepStart(int dsdelay)
addLog(LOG_LEVEL_INFO, F("SLEEP: Powering down to deepsleep..."));
RTC.deepSleepState = 1;
prepareShutdown();
prepareShutdown(ESPEasy_Scheduler::IntendedRebootReason_e::DeepSleep);
#if defined(ESP8266)
# if defined(CORE_POST_2_5_0)
+1 -1
View File
@@ -261,7 +261,7 @@ void ResetFactory()
intent_to_reboot = true;
WifiDisconnect(); // this will store empty ssid/wpa into sdk storage
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
reboot();
reboot(ESPEasy_Scheduler::IntendedRebootReason_e::ResetFactory);
}
+1 -1
View File
@@ -329,7 +329,7 @@ void checkResetFactoryPin() {
if (factoryResetCounter > 3) {
// normal reboot
reboot();
reboot(ESPEasy_Scheduler::IntendedRebootReason_e::ResetFactoryPinActive);
}
factoryResetCounter = 0; // count was < 3, reset counter
}
+4 -4
View File
@@ -315,7 +315,7 @@ bool timeStringToSeconds(const String& tBuf, int& time_seconds) {
/********************************************************************************************\
Delayed reboot, in case of issues, do not reboot with high frequency as it might not help...
\*********************************************************************************************/
void delayedReboot(int rebootDelay)
void delayedReboot(int rebootDelay, ESPEasy_Scheduler::IntendedRebootReason_e reason)
{
// Direct Serial is allowed here, since this is only an emergency task.
while (rebootDelay != 0)
@@ -325,11 +325,11 @@ void delayedReboot(int rebootDelay)
rebootDelay--;
delay(1000);
}
reboot();
reboot(reason);
}
void reboot() {
prepareShutdown();
void reboot(ESPEasy_Scheduler::IntendedRebootReason_e reason) {
prepareShutdown(reason);
#if defined(ESP32)
ESP.restart();
#else // if defined(ESP32)
+3 -2
View File
@@ -5,6 +5,7 @@
#include "../DataStructs/PinMode.h"
#include "../../ESPEasy-Globals.h"
#include "../Helpers/Scheduler.h"
@@ -131,9 +132,9 @@ bool timeStringToSeconds(const String& tBuf,
/********************************************************************************************\
Delayed reboot, in case of issues, do not reboot with high frequency as it might not help...
\*********************************************************************************************/
void delayedReboot(int rebootDelay);
void delayedReboot(int rebootDelay, ESPEasy_Scheduler::IntendedRebootReason_e reason = ESPEasy_Scheduler::IntendedRebootReason_e::DelayedReboot);
void reboot();
void reboot(ESPEasy_Scheduler::IntendedRebootReason_e reason);
void SendValueLogger(taskIndex_t TaskIndex);
+1 -1
View File
@@ -85,7 +85,7 @@ void ArduinoOTAInit()
else if (error == OTA_END_ERROR) { serialPrintln(F("End Failed")); }
delay(100);
reboot();
reboot(ESPEasy_Scheduler::IntendedRebootReason_e::OTA_error);
});
ArduinoOTA.begin();
+4 -3
View File
@@ -99,7 +99,7 @@ void runOncePerSecond()
if (Settings.ConnectionFailuresThreshold)
if (connectionFailures > Settings.ConnectionFailuresThreshold)
delayedReboot(60);
delayedReboot(60, ESPEasy_Scheduler::IntendedRebootReason_e::DelayedReboot);
if (cmd_within_mainloop != 0)
{
@@ -112,7 +112,7 @@ void runOncePerSecond()
}
case CMD_REBOOT:
{
reboot();
reboot(ESPEasy_Scheduler::IntendedRebootReason_e::CommandReboot);
break;
}
}
@@ -401,7 +401,7 @@ void updateLoopStats_30sec(byte loglevel) {
/********************************************************************************************\
Clean up all before going to sleep or reboot.
\*********************************************************************************************/
void prepareShutdown()
void prepareShutdown(ESPEasy_Scheduler::IntendedRebootReason_e reason)
{
#ifdef USES_MQTT
runPeriodicalMQTT(); // Flush outstanding MQTT messages
@@ -412,6 +412,7 @@ void prepareShutdown()
ESPEASY_FS.end();
delay(100); // give the node time to flush all before reboot or sleep
node_time.now();
Scheduler.markIntendedReboot(reason);
saveToRTC();
}
+2 -1
View File
@@ -5,6 +5,7 @@
#include "../../ESPEasy_common.h"
#include "../Globals/CPlugins.h"
#include "../Helpers/Scheduler.h"
/*********************************************************************************************\
* Tasks that run 50 times per second
@@ -52,7 +53,7 @@ void updateLoopStats_30sec(byte loglevel);
/********************************************************************************************\
Clean up all before going to sleep or reboot.
\*********************************************************************************************/
void prepareShutdown();
void prepareShutdown(ESPEasy_Scheduler::IntendedRebootReason_e reason);
+29 -1
View File
@@ -22,6 +22,7 @@
#define GPIO_TIMER 4
#define PLUGIN_TIMER 5
#define RULES_TIMER 6
#define REBOOT_TIMER 15 // Used to show intended reboot
String ESPEasy_Scheduler::toString(ESPEasy_Scheduler::IntervalTimer_e timer) {
@@ -74,6 +75,27 @@ String ESPEasy_Scheduler::toString(ESPEasy_Scheduler::IntervalTimer_e timer) {
#endif
}
String ESPEasy_Scheduler::toString(ESPEasy_Scheduler::IntendedRebootReason_e reason) {
switch(reason) {
case IntendedRebootReason_e::DeepSleep: return F("DeepSleep");
case IntendedRebootReason_e::DelayedReboot: return F("DelayedReboot");
case IntendedRebootReason_e::ResetFactory: return F("ResetFactory");
case IntendedRebootReason_e::ResetFactoryPinActive: return F("ResetFactoryPinActive");
case IntendedRebootReason_e::ResetFactoryCommand: return F("ResetFactoryCommand");
case IntendedRebootReason_e::CommandReboot: return F("CommandReboot");
case IntendedRebootReason_e::RestoreSettings: return F("RestoreSettings");
case IntendedRebootReason_e::OTA_error: return F("OTA_error");
case IntendedRebootReason_e::ConnectionFailuresThreshold: return F("ConnectionFailuresThreshold");
}
return String(static_cast<int>(reason));
}
void ESPEasy_Scheduler::markIntendedReboot(ESPEasy_Scheduler::IntendedRebootReason_e reason) {
const unsigned long mixed_id = getMixedId(REBOOT_TIMER, static_cast<unsigned long>(reason));
RTC.lastMixedSchedulerId = mixed_id;
saveToRTC();
}
/*********************************************************************************************\
* Generic Timer functions.
\*********************************************************************************************/
@@ -103,7 +125,7 @@ String ESPEasy_Scheduler::decodeSchedulerId(unsigned long mixed_id) {
const unsigned long id = decodeSchedulerId(mixed_id, timerType);
String idStr = String(id);
String result = String(timerType);
result.reserve(32);
result.reserve(64);
switch (timerType) {
case CONST_INTERVAL_TIMER:
result = F("Const Interval: ");
@@ -172,6 +194,12 @@ String ESPEasy_Scheduler::decodeSchedulerId(unsigned long mixed_id) {
result += timerID;
return result;
}
case REBOOT_TIMER:
{
result = F("Intended Reboot: ");
result += toString(static_cast<ESPEasy_Scheduler::IntendedRebootReason_e>(id));
return result;
}
}
result += F(" timer, id: ");
result += idStr;
+17
View File
@@ -60,6 +60,23 @@ public:
NotificationPlugin
};
enum class IntendedRebootReason_e {
DeepSleep,
DelayedReboot,
ResetFactory,
ResetFactoryPinActive,
ResetFactoryCommand,
CommandReboot,
RestoreSettings,
OTA_error,
ConnectionFailuresThreshold,
};
static String toString(IntendedRebootReason_e reason);
void markIntendedReboot(IntendedRebootReason_e reason);
/*********************************************************************************************\
* Generic Timer functions.