Add reboot info text when configuration is changed

This commit is contained in:
fvanroie 2022-01-10 05:03:09 +01:00
parent a7a437f48f
commit 5e0198efc1
8 changed files with 43 additions and 26 deletions

View File

@ -146,6 +146,7 @@
#define D_HTTP_MAIN_MENU "Main Menu" #define D_HTTP_MAIN_MENU "Main Menu"
#define D_HTTP_REBOOT "Restart" #define D_HTTP_REBOOT "Restart"
#define D_HTTP_CONFIGURATION "Configuration" #define D_HTTP_CONFIGURATION "Configuration"
#define D_HTTP_CONFIG_CHANGED "Configuration has changed, please click <a href='/reboot'>Restart</a> to save changes to flash."
#define D_HTTP_SENDING_PAGE "Sent %S page to %s" // New #define D_HTTP_SENDING_PAGE "Sent %S page to %s" // New
#define D_HTTP_FOOTER "by Francis Van Roie" #define D_HTTP_FOOTER "by Francis Van Roie"

View File

@ -146,6 +146,7 @@
#define D_HTTP_MAIN_MENU "Menú principal" #define D_HTTP_MAIN_MENU "Menú principal"
#define D_HTTP_REBOOT "Reiniciar" #define D_HTTP_REBOOT "Reiniciar"
#define D_HTTP_CONFIGURATION "Configuración" #define D_HTTP_CONFIGURATION "Configuración"
#define D_HTTP_CONFIG_CHANGED "Configuration has changed, please click <a href='/reboot'>Restart</a> to save changes to flash."
#define D_HTTP_SENDING_PAGE "Se envió pagina %S a %s" // New #define D_HTTP_SENDING_PAGE "Se envió pagina %S a %s" // New
#define D_HTTP_FOOTER "por Francis Van Roie" #define D_HTTP_FOOTER "por Francis Van Roie"

View File

@ -146,6 +146,7 @@
#define D_HTTP_MAIN_MENU "Menu principal" #define D_HTTP_MAIN_MENU "Menu principal"
#define D_HTTP_REBOOT "Redémarrer" #define D_HTTP_REBOOT "Redémarrer"
#define D_HTTP_CONFIGURATION "Configuration" #define D_HTTP_CONFIGURATION "Configuration"
#define D_HTTP_CONFIG_CHANGED "Configuration has changed, please click <a href='/reboot'>Restart</a> to save changes to flash."
#define D_HTTP_SENDING_PAGE "La page %S a été envoyée à %s" #define D_HTTP_SENDING_PAGE "La page %S a été envoyée à %s"
#define D_HTTP_FOOTER "par Francis Van Roie" #define D_HTTP_FOOTER "par Francis Van Roie"

View File

@ -146,6 +146,7 @@
#define D_HTTP_MAIN_MENU "Főmenü" #define D_HTTP_MAIN_MENU "Főmenü"
#define D_HTTP_REBOOT "Újraindítás" #define D_HTTP_REBOOT "Újraindítás"
#define D_HTTP_CONFIGURATION "Beállítások" #define D_HTTP_CONFIGURATION "Beállítások"
#define D_HTTP_CONFIG_CHANGED "Configuration has changed, please click <a href='/reboot'>Restart</a> to save changes to flash."
#define D_HTTP_SENDING_PAGE "%S oldal küldése %s-re" #define D_HTTP_SENDING_PAGE "%S oldal küldése %s-re"
#define D_HTTP_FOOTER "készítette: Francis Van Roie" #define D_HTTP_FOOTER "készítette: Francis Van Roie"

View File

@ -146,6 +146,7 @@
#define D_HTTP_MAIN_MENU "Hoofdmenu" #define D_HTTP_MAIN_MENU "Hoofdmenu"
#define D_HTTP_REBOOT "Herstarten" #define D_HTTP_REBOOT "Herstarten"
#define D_HTTP_CONFIGURATION "Configuratie" #define D_HTTP_CONFIGURATION "Configuratie"
#define D_HTTP_CONFIG_CHANGED "Configuration has changed, please click <a href='/reboot'>Restart</a> to save changes to flash."
#define D_HTTP_SENDING_PAGE "Pagina %S verstuurd naar %s" // New #define D_HTTP_SENDING_PAGE "Pagina %S verstuurd naar %s" // New
#define D_HTTP_FOOTER "door Francis Van Roie" #define D_HTTP_FOOTER "door Francis Van Roie"

View File

@ -147,6 +147,7 @@
#define D_HTTP_MAIN_MENU "Menu Principal" #define D_HTTP_MAIN_MENU "Menu Principal"
#define D_HTTP_REBOOT "Reiniciar" #define D_HTTP_REBOOT "Reiniciar"
#define D_HTTP_CONFIGURATION "Configuração" #define D_HTTP_CONFIGURATION "Configuração"
#define D_HTTP_CONFIG_CHANGED "Configuration has changed, please click <a href='/reboot'>Restart</a> to save changes to flash."
#define D_HTTP_SENDING_PAGE "Foi enviado página %S a %s" #define D_HTTP_SENDING_PAGE "Foi enviado página %S a %s"
#define D_HTTP_FOOTER "por Francis Van Roie" #define D_HTTP_FOOTER "por Francis Van Roie"

View File

@ -146,6 +146,7 @@
#define D_HTTP_MAIN_MENU "Meniu principal" #define D_HTTP_MAIN_MENU "Meniu principal"
#define D_HTTP_REBOOT "Repornire" #define D_HTTP_REBOOT "Repornire"
#define D_HTTP_CONFIGURATION "Setări" #define D_HTTP_CONFIGURATION "Setări"
#define D_HTTP_CONFIG_CHANGED "Configuration has changed, please click <a href='/reboot'>Restart</a> to save changes to flash."
#define D_HTTP_SENDING_PAGE "Pagina %S trimisă la %s" #define D_HTTP_SENDING_PAGE "Pagina %S trimisă la %s"
#define D_HTTP_FOOTER "de Francis Van Roie" #define D_HTTP_FOOTER "de Francis Van Roie"

View File

@ -301,52 +301,54 @@ static void webSendHeader(const char* nodename, uint32_t httpdatalength, bool go
#endif #endif
} }
void saveConfig() bool saveConfig()
{ {
if(webServer.method() == HTTP_POST) { bool updated = false;
if(webServer.hasArg(PSTR("save"))) {
if(webServer.method() == HTTP_POST && webServer.hasArg(PSTR("save"))) {
String save = webServer.arg(PSTR("save")); String save = webServer.arg(PSTR("save"));
StaticJsonDocument<256> settings; StaticJsonDocument<256> settings;
for(int i = 0; i < webServer.args(); i++) settings[webServer.argName(i)] = webServer.arg(i); for(int i = 0; i < webServer.args(); i++) settings[webServer.argName(i)] = webServer.arg(i);
if(save == String(PSTR("hasp"))) { if(save == String(PSTR("hasp"))) {
haspSetConfig(settings.as<JsonObject>()); updated = haspSetConfig(settings.as<JsonObject>());
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
} else if(save == String(PSTR("mqtt"))) { } else if(save == String(PSTR("mqtt"))) {
mqttSetConfig(settings.as<JsonObject>()); updated = mqttSetConfig(settings.as<JsonObject>());
#endif #endif
} else if(save == String(PSTR("gui"))) { } else if(save == String(PSTR("gui"))) {
settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg(PSTR("cur")); settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg(PSTR("cur"));
settings[FPSTR(FP_GUI_INVERT)] = webServer.hasArg(PSTR("inv")); settings[FPSTR(FP_GUI_INVERT)] = webServer.hasArg(PSTR("inv"));
guiSetConfig(settings.as<JsonObject>()); updated = guiSetConfig(settings.as<JsonObject>());
} else if(save == String(PSTR("debug"))) { } else if(save == String(PSTR("debug"))) {
settings[FPSTR(FP_DEBUG_ANSI)] = webServer.hasArg(PSTR("ansi")); settings[FPSTR(FP_DEBUG_ANSI)] = webServer.hasArg(PSTR("ansi"));
debugSetConfig(settings.as<JsonObject>()); updated = debugSetConfig(settings.as<JsonObject>());
} else if(save == String(PSTR("http"))) { } else if(save == String(PSTR("http"))) {
httpSetConfig(settings.as<JsonObject>()); updated = httpSetConfig(settings.as<JsonObject>());
// Password might have changed // Password might have changed
if(!httpIsAuthenticated(F("config"))) return; if(!httpIsAuthenticated(F("config"))) return updated;
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
} else if(save == String(PSTR("wifi"))) { } else if(save == String(PSTR("wifi"))) {
wifiSetConfig(settings.as<JsonObject>()); updated = wifiSetConfig(settings.as<JsonObject>());
#endif #endif
} }
} }
}
return updated;
} }
static void webHandleRoot() static void webHandleRoot()
{ {
if(!httpIsAuthenticated(F("root"))) return; if(!httpIsAuthenticated(F("root"))) return;
bool updated = saveConfig();
saveConfig();
{ {
String httpMessage((char*)0); String httpMessage((char*)0);
httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage.reserve(HTTP_PAGE_SIZE);
@ -354,6 +356,10 @@ static void webHandleRoot()
httpMessage += haspDevice.get_hostname(); httpMessage += haspDevice.get_hostname();
httpMessage += F("</h1><hr>"); httpMessage += F("</h1><hr>");
if(updated) {
httpMessage += F("<p class='info'>" D_HTTP_CONFIG_CHANGED "</p>");
}
httpMessage += F("<a href='/config/hasp'>" D_HTTP_HASP_DESIGN "</a>"); httpMessage += F("<a href='/config/hasp'>" D_HTTP_HASP_DESIGN "</a>");
httpMessage += F("<a href='/screenshot'>" D_HTTP_SCREENSHOT "</a>"); httpMessage += F("<a href='/screenshot'>" D_HTTP_SCREENSHOT "</a>");
httpMessage += F("<a href='/info'>" D_HTTP_INFORMATION "</a>"); httpMessage += F("<a href='/info'>" D_HTTP_INFORMATION "</a>");
@ -966,7 +972,7 @@ static void webHandleConfig()
{ // http://plate01/config { // http://plate01/config
if(!httpIsAuthenticated(F("config"))) return; if(!httpIsAuthenticated(F("config"))) return;
saveConfig(); bool updated = saveConfig();
// Reboot after saving wifi config in AP mode // Reboot after saving wifi config in AP mode
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) #if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
@ -982,6 +988,10 @@ static void webHandleConfig()
httpMessage += haspDevice.get_hostname(); httpMessage += haspDevice.get_hostname();
httpMessage += F("</h1><hr>"); httpMessage += F("</h1><hr>");
if(updated) {
httpMessage += F("<p class='info'>" D_HTTP_CONFIG_CHANGED "</p>");
}
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
httpMessage += F("<a href='/config/wifi'>" D_HTTP_WIFI_SETTINGS "</a>"); httpMessage += F("<a href='/config/wifi'>" D_HTTP_WIFI_SETTINGS "</a>");
#endif #endif