add restart reason to sysinfo page
This commit is contained in:
@@ -61,6 +61,7 @@ file(GLOB SRCFILES
|
||||
PreferencesKeys.h
|
||||
Gpio.cpp
|
||||
Logger.cpp
|
||||
RestartReason.h
|
||||
# include/RTOS.h
|
||||
lib/WiFiManager/WiFiManager.cpp
|
||||
lib/WiFiManager/wm_consts_en.h
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "networkDevices/WifiDevice.h"
|
||||
#include "Logger.h"
|
||||
#include "Config.h"
|
||||
#include "RestartReason.h"
|
||||
|
||||
|
||||
Network* Network::_inst = nullptr;
|
||||
@@ -187,7 +188,7 @@ bool Network::update()
|
||||
{
|
||||
if(_restartOnDisconnect && millis() > 60000)
|
||||
{
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
}
|
||||
|
||||
Log->println(F("Network not connected. Trying reconnect."));
|
||||
@@ -199,7 +200,7 @@ bool Network::update()
|
||||
strcpy(WiFi_fallbackDetect, "wifi_fallback");
|
||||
Log->println("Network device has a critical failure, enable fallback to Wifi and reboot.");
|
||||
delay(200);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::NetworkDeviceCriticalFailure);
|
||||
break;
|
||||
case ReconnectStatus::Success:
|
||||
memset(WiFi_fallbackDetect, 0, sizeof(WiFi_fallbackDetect));
|
||||
@@ -218,7 +219,7 @@ bool Network::update()
|
||||
{
|
||||
Log->println("Network timeout has been reached, restarting ...");
|
||||
delay(200);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::NetworkTimeoutWatchdog);
|
||||
}
|
||||
|
||||
bool success = reconnect();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "PreferencesKeys.h"
|
||||
#include "Pins.h"
|
||||
#include "Logger.h"
|
||||
#include "RestartReason.h"
|
||||
|
||||
NetworkLock::NetworkLock(Network* network, Preferences* preferences)
|
||||
: _network(network),
|
||||
@@ -81,7 +82,7 @@ void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const uns
|
||||
{
|
||||
Log->println(F("Restart requested via MQTT."));
|
||||
delay(200);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::RequestedViaMqtt);
|
||||
}
|
||||
|
||||
if(processActions && comparePrefixedPath(topic, mqtt_topic_lock_action))
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "PreferencesKeys.h"
|
||||
#include "MqttTopics.h"
|
||||
#include "Logger.h"
|
||||
#include "RestartReason.h"
|
||||
#include <NukiOpenerUtils.h>
|
||||
|
||||
NukiOpenerWrapper* nukiOpenerInst;
|
||||
@@ -108,7 +109,7 @@ void NukiOpenerWrapper::update()
|
||||
Log->print((millis() - _nukiOpener.getLastReceivedBeaconTs()) / 1000);
|
||||
Log->println(" seconds, restarting device.");
|
||||
delay(200);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::BLEBeaconWatchdog);
|
||||
}
|
||||
|
||||
_nukiOpener.updateConnectionState();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "PreferencesKeys.h"
|
||||
#include "MqttTopics.h"
|
||||
#include "Logger.h"
|
||||
#include "RestartReason.h"
|
||||
#include <NukiLockUtils.h>
|
||||
|
||||
NukiWrapper* nukiInst;
|
||||
@@ -134,7 +135,7 @@ void NukiWrapper::update()
|
||||
Log->print((millis() - _nukiLock.getLastReceivedBeaconTs()) / 1000);
|
||||
Log->println(" seconds, restarting device.");
|
||||
delay(200);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::BLEBeaconWatchdog);
|
||||
}
|
||||
|
||||
_nukiLock.updateConnectionState();
|
||||
|
||||
68
RestartReason.h
Normal file
68
RestartReason.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
enum class RestartReason
|
||||
{
|
||||
RequestedViaMqtt,
|
||||
BLEBeaconWatchdog,
|
||||
RestartOnDisconnectWatchdog,
|
||||
RestartIntervalWatchdog,
|
||||
NetworkTimeoutWatchdog,
|
||||
WifiInitFailed,
|
||||
ReconfigureWifi,
|
||||
NetworkDeviceCriticalFailure,
|
||||
ConfigurationUpdated,
|
||||
RestartTimer,
|
||||
OTATimeout,
|
||||
DeviceUnpaired
|
||||
};
|
||||
|
||||
#define RESTART_REASON_VALID_DETECT 0xa00ab00bc00bd00d;
|
||||
|
||||
extern int restartReason;
|
||||
extern uint64_t restartReasonValid;
|
||||
|
||||
inline static void restartEsp(RestartReason reason)
|
||||
{
|
||||
restartReason = (int)reason;
|
||||
restartReasonValid = RESTART_REASON_VALID_DETECT;
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
inline static String getRestartReasion()
|
||||
{
|
||||
uint64_t cmp = RESTART_REASON_VALID_DETECT;
|
||||
if(restartReasonValid != cmp)
|
||||
{
|
||||
return "UnknownNoRestartRegistered";
|
||||
}
|
||||
|
||||
switch((RestartReason)restartReason)
|
||||
{
|
||||
case RestartReason::RequestedViaMqtt:
|
||||
return "RequestedViaMqtt";
|
||||
case RestartReason::BLEBeaconWatchdog:
|
||||
return "BLEBeaconWatchdog";
|
||||
case RestartReason::RestartOnDisconnectWatchdog:
|
||||
return "RestartOnDisconnectWatchdog";
|
||||
case RestartReason::RestartIntervalWatchdog:
|
||||
return "RestartIntervalWatchdog";
|
||||
case RestartReason::NetworkTimeoutWatchdog:
|
||||
return "NetworkTimeoutWatchdog";
|
||||
case RestartReason::WifiInitFailed:
|
||||
return "WifiInitFailed";
|
||||
case RestartReason::ReconfigureWifi:
|
||||
return "ReconfigureWifi";
|
||||
case RestartReason::NetworkDeviceCriticalFailure:
|
||||
return "NetworkDeviceCriticalFailure";
|
||||
case RestartReason::ConfigurationUpdated:
|
||||
return "ConfigurationUpdated";
|
||||
case RestartReason::RestartTimer:
|
||||
return "RestartTimer";
|
||||
case RestartReason::OTATimeout:
|
||||
return "OTATimeout";
|
||||
case RestartReason::DeviceUnpaired:
|
||||
return "DeviceUnpaired";
|
||||
default:
|
||||
return "Unknown: " + restartReason;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "hardware/WifiEthServer.h"
|
||||
#include "Logger.h"
|
||||
#include "Config.h"
|
||||
#include "RestartReason.h"
|
||||
#include <esp_task_wdt.h>
|
||||
|
||||
WebCfgServer::WebCfgServer(NukiWrapper* nuki, NukiOpenerWrapper* nukiOpener, Network* network, EthServer* ethServer, Preferences* preferences, bool allowRestartToPortal)
|
||||
@@ -119,8 +120,8 @@ void WebCfgServer::initialize()
|
||||
return _server.requestAuthentication();
|
||||
}
|
||||
String message = "";
|
||||
bool restartEsp = processArgs(message);
|
||||
if(restartEsp)
|
||||
bool restart = processArgs(message);
|
||||
if(restart)
|
||||
{
|
||||
String response = "";
|
||||
buildConfirmHtml(response, message);
|
||||
@@ -128,7 +129,7 @@ void WebCfgServer::initialize()
|
||||
Log->println(F("Restarting"));
|
||||
|
||||
waitAndProcess(true, 1000);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::ConfigurationUpdated);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -176,7 +177,7 @@ void WebCfgServer::initialize()
|
||||
Log->println(F("Restarting"));
|
||||
|
||||
waitAndProcess(true, 1000);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::ConfigurationUpdated);
|
||||
});
|
||||
_server.on("/heapoff", [&]() {
|
||||
_preferences->putBool(preference_publish_heap, false);
|
||||
@@ -187,7 +188,7 @@ void WebCfgServer::initialize()
|
||||
Log->println(F("Restarting"));
|
||||
|
||||
waitAndProcess(true, 1000);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::ConfigurationUpdated);
|
||||
});
|
||||
|
||||
_server.begin();
|
||||
@@ -475,7 +476,7 @@ void WebCfgServer::update()
|
||||
{
|
||||
Log->println(F("OTA time out, restarting"));
|
||||
delay(200);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::OTATimeout);
|
||||
}
|
||||
|
||||
if(!_enabled) return;
|
||||
@@ -763,6 +764,14 @@ void WebCfgServer::buildInfoHtml(String &response)
|
||||
response.concat(esp_get_free_heap_size());
|
||||
response.concat("\n");
|
||||
|
||||
response.concat("Restart reason FW: ");
|
||||
response.concat(getRestartReasion());
|
||||
response.concat("\n");
|
||||
|
||||
// response.concat("Restart reason ESP: ");
|
||||
// response.concat(getRestartReasion());
|
||||
// response.concat("\n");
|
||||
|
||||
response.concat("</pre> </BODY></HTML>");
|
||||
}
|
||||
|
||||
@@ -801,7 +810,7 @@ void WebCfgServer::processUnpair(bool opener)
|
||||
_nukiOpener->unpair();
|
||||
}
|
||||
waitAndProcess(false, 1000);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::DeviceUnpaired);
|
||||
}
|
||||
|
||||
void WebCfgServer::buildHtmlHeader(String &response)
|
||||
|
||||
6
main.cpp
6
main.cpp
@@ -12,6 +12,7 @@
|
||||
#include "Gpio.h"
|
||||
#include "Logger.h"
|
||||
#include "Config.h"
|
||||
#include "RestartReason.h"
|
||||
|
||||
Network* network = nullptr;
|
||||
NetworkLock* networkLock = nullptr;
|
||||
@@ -28,6 +29,9 @@ bool lockEnabled = false;
|
||||
bool openerEnabled = false;
|
||||
unsigned long restartTs = (2^32) - 5 * 60000;
|
||||
|
||||
RTC_NOINIT_ATTR int restartReason;
|
||||
RTC_NOINIT_ATTR uint64_t restartReasonValid;
|
||||
|
||||
void networkTask(void *pvParameters)
|
||||
{
|
||||
while(true)
|
||||
@@ -92,7 +96,7 @@ void checkMillisTask(void *pvParameters)
|
||||
{
|
||||
Log->println(F("Restart timer expired, restarting device."));
|
||||
delay(200);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::RestartTimer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../Logger.h"
|
||||
#include "../MqttTopics.h"
|
||||
#include "espMqttClient.h"
|
||||
#include "../RestartReason.h"
|
||||
|
||||
RTC_NOINIT_ATTR char WiFiDevice_reconfdetect[17];
|
||||
|
||||
@@ -80,7 +81,7 @@ void WifiDevice::initialize()
|
||||
if(!res) {
|
||||
Log->println(F("Failed to connect. Wait for ESP restart."));
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::WifiInitFailed);
|
||||
}
|
||||
else {
|
||||
Log->print(F("WiFi connected: "));
|
||||
@@ -103,7 +104,7 @@ void WifiDevice::reconfigure()
|
||||
{
|
||||
strcpy(WiFiDevice_reconfdetect, "reconfigure_wifi");
|
||||
delay(200);
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::ReconfigureWifi);
|
||||
}
|
||||
|
||||
void WifiDevice::printError()
|
||||
@@ -143,7 +144,7 @@ void WifiDevice::onDisconnected()
|
||||
{
|
||||
if(millis() > 60000)
|
||||
{
|
||||
ESP.restart();
|
||||
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user