diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp index bfd23808..fc77fb3e 100644 --- a/src/hasp_http.cpp +++ b/src/hasp_http.cpp @@ -3,11 +3,13 @@ #include "ArduinoJson.h" #include "hasp_log.h" +#include "hasp_gui.h" #include "hasp_debug.h" #include "hasp_http.h" #include "hasp_mqtt.h" #include "hasp_wifi.h" #include "hasp_config.h" +#include "hasp_dispatch.h" #include "hasp.h" #if defined(ARDUINO_ARCH_ESP32) @@ -248,13 +250,9 @@ void httpHandleReboot() webSendPage(nodename, httpMessage.length(), true); webServer.sendContent(httpMessage); // len webServer.sendContent_P(HTTP_END); // 20 - delay(500); - debugPrintln(PSTR("HTTP: Reboot device")); - // haspProcessAttribute(F("p[0].b[1].txt"), F("\"Rebooting...\"")); - - delay(500); - haspReset(true); + delay(200); + dispatchCommand(F("reboot")); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -677,7 +675,7 @@ void webHandleConfig() F("

"); httpMessage += - F("

"); + F("

"); httpMessage += F("

"); @@ -741,6 +739,35 @@ void webHandleMqttConfig() } #endif +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleGuiConfig() +{ // http://plate01/config/wifi + if(!httpIsAuthenticated(F("/config/gui"))) return; + + DynamicJsonDocument settings(256); + // guiGetConfig(settings.to()); + + char buffer[64]; + String nodename = haspGetNodename(); + String httpMessage((char *)0); + httpMessage.reserve(1024); + + httpMessage += String(F("
")); + httpMessage += F("

"); + + httpMessage += PSTR("

"); + + httpMessage += + PSTR("

"); + + webSendPage(nodename, httpMessage.length(), false); + webServer.sendContent(httpMessage); // len + webServer.sendContent_P(HTTP_END); // 20 + + if(webServer.hasArg(F("action"))) dispatchCommand(webServer.arg(F("action"))); +} + //////////////////////////////////////////////////////////////////////////////////////////////////// #if LV_USE_HASP_WIFI > 0 void webHandleWifiConfig() @@ -826,12 +853,12 @@ void webHandleHaspConfig() String httpMessage((char *)0); httpMessage.reserve(1024); - httpMessage += String(F("

")); + httpMessage += F("

"); httpMessage += F("


"); - httpMessage += String(F("
")); - httpMessage += String(F("

UI Theme (required)"); uint8_t themeid = settings[FPSTR(F_CONFIG_THEME)].as(); httpMessage += getOption(0, F("Built-in"), themeid == 0); @@ -857,15 +884,15 @@ void webHandleHaspConfig() #if LV_USE_THEME_TEMPL == 1 httpMessage += getOption(7, F("Template"), themeid == 7); #endif - httpMessage += String(F("
")); + httpMessage += F("
"); httpMessage += - "Hue

"; + F("Hue

"); + httpMessage += F("

Default Font")); #if defined(ARDUINO_ARCH_ESP32) debugPrintln(PSTR("HTTP: Listing files on the internal flash:")); File root = SPIFFS.open("/"); @@ -889,14 +916,16 @@ void webHandleHaspConfig() file.close(); } #endif - httpMessage += String(F("

")); + httpMessage += F("

"); - httpMessage += String(F("

Pages File (required)"; - httpMessage += String(F("
Startup Page (required)

"; + httpMessage += F("

Pages File (required)
Startup Page (required)

"); httpMessage += F("

"); @@ -916,7 +945,7 @@ void httpHandleNotFound() debugPrintln(String(F("HTTP: Sending 404 to client connected from: ")) + webServer.client().remoteIP().toString()); String httpMessage((char *)0); - httpMessage.reserve(128); + httpMessage.reserve(512); httpMessage += F("File Not Found\n\nURI: "); httpMessage += webServer.uri(); httpMessage += F("\nMethod: "); @@ -1007,7 +1036,7 @@ void httpHandleResetConfig() if(resetConfirmed) { delay(250); // configClearSaved(); - haspReset(false); // Do not save the current config + haspReboot(false); // Do not save the current config } } @@ -1048,6 +1077,7 @@ void httpSetup(const JsonObject & settings) webServer.on(F("/config"), webHandleConfig); webServer.on(F("/config/hasp"), webHandleHaspConfig); webServer.on(F("/config/http"), webHandleHttpConfig); + webServer.on(F("/config/gui"), webHandleGuiConfig); #if LV_USE_HASP_MQTT > 0 webServer.on(F("/config/mqtt"), webHandleMqttConfig); #endif