From 2a1355319daf498bade98866f548763827fd38e0 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sun, 30 Jul 2023 19:45:46 +0200 Subject: [PATCH] show success page after firmware update & reboot after initial wifi setup --- include/pages.h | 3 +- src/main.cpp | 5 ++++ src/pages.cpp | 79 +++++++++++++++++++++++++++++++------------------ 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/include/pages.h b/include/pages.h index 1774a67..3d00278 100644 --- a/include/pages.h +++ b/include/pages.h @@ -12,7 +12,7 @@ #include "debug.h" void setupPages(AsyncWebServer* server, PhaseSwitch *phaseSwitch, Config *config, WiFiManager *wm); - void sendResponseHeader(AsyncResponseStream *response, const char *title); + void sendResponseHeader(AsyncResponseStream *response, const char *title, bool inlineStyle = false); void sendResponseTrailer(AsyncResponseStream *response); void sendButton(AsyncResponseStream *response, const char *title, const char *action, const char *css = ""); void sendPostButton(AsyncResponseStream *response, const char *title, const char *action); @@ -22,6 +22,7 @@ void sendTableRow(AsyncResponseStream *response, const char *name, String value); void sendTableRow(AsyncResponseStream *response, const char *name, const char *value); void sendDebugForm(AsyncResponseStream *response, String slaveId, String reg, String function, String count); + void sendMinCss(AsyncResponseStream *response); const String ErrorName(Modbus::Error code); const String WiFiQuality(int rssiValue); const String ChargingState(uint16_t state); diff --git a/src/main.cpp b/src/main.cpp index 5b637d5..1176775 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,7 +32,12 @@ void setup() { digitalWrite(PIN_FACTORY_LED, LOW); wm.setClass("invert"); + auto reboot = false; + wm.setAPCallback([&reboot](WiFiManager *wifiManager){reboot = true;}); wm.autoConnect(); + if (reboot){ + ESP.restart(); + } MBUlogLvl = LOG_LEVEL_WARNING; LOGDEVICE = &debugOut; dbgln("[wifi] finished"); diff --git a/src/pages.cpp b/src/pages.cpp index f3e17c1..adb9c1a 100644 --- a/src/pages.cpp +++ b/src/pages.cpp @@ -213,6 +213,9 @@ void setupPages(AsyncWebServer *server, PhaseSwitch *phaseSwitch, Config *config request->send(response); }); server->on("/update", HTTP_POST, [](AsyncWebServerRequest *request){ + request->onDisconnect([](){ + ESP.restart(); + }); dbgln("[webserver] OTA finished"); if (Update.hasError()){ auto *response = request->beginResponse(500, "text/plain", "Ota failed"); @@ -220,9 +223,14 @@ void setupPages(AsyncWebServer *server, PhaseSwitch *phaseSwitch, Config *config request->send(response); } else{ - request->redirect("/"); + auto *response = request->beginResponseStream("text/html"); + response->addHeader("Connection", "close"); + sendResponseHeader(response, "Firmware Update", true); + response->print("

Update successful.

"); + sendButton(response, "Back", "/"); + sendResponseTrailer(response); + request->send(response); } - ESP.restart(); }, [&](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ dbg("[webserver] OTA progress ");dbgln(index); if (!index) { @@ -286,31 +294,9 @@ void setupPages(AsyncWebServer *server, PhaseSwitch *phaseSwitch, Config *config } } dbgln("[webserver] GET /style.css"); - auto *response = request->beginResponse(200, "text/css", - "body{" - "font-family:sans-serif;" - "text-align: center;" - "background: #252525;" - "color: #faffff;" - "}" - "#content{" - "display: inline-block;" - "min-width: 340px;" - "}" - "button{" - "width: 100%;" - "line-height: 2.4rem;" - "background: #1fa3ec;" - "border: 0;" - "border-radius: 0.3rem;" - "font-size: 1.2rem;" - "-webkit-transition-duration: 0.4s;" - "transition-duration: 0.4s;" - "color: #faffff;" - "}" - "button:hover{" - "background: #0e70a4;" - "}" + auto *response = request->beginResponseStream("text/css"); + sendMinCss(response); + response->print( "button.r{" "background: #d43535;" "}" @@ -340,14 +326,49 @@ void setupPages(AsyncWebServer *server, PhaseSwitch *phaseSwitch, Config *config }); } -void sendResponseHeader(AsyncResponseStream *response, const char *title){ +void sendMinCss(AsyncResponseStream *response){ + response->print("body{" + "font-family:sans-serif;" + "text-align: center;" + "background: #252525;" + "color: #faffff;" + "}" + "#content{" + "display: inline-block;" + "min-width: 340px;" + "}" + "button{" + "width: 100%;" + "line-height: 2.4rem;" + "background: #1fa3ec;" + "border: 0;" + "border-radius: 0.3rem;" + "font-size: 1.2rem;" + "-webkit-transition-duration: 0.4s;" + "transition-duration: 0.4s;" + "color: #faffff;" + "}" + "button:hover{" + "background: #0e70a4;" + "}"); +} + +void sendResponseHeader(AsyncResponseStream *response, const char *title, bool inlineStyle){ response->print("" "" "" "" ""); response->printf("Heidelberg Phase Switch - %s", title); - response->print("" + if (inlineStyle){ + response->print(""); + } + else{ + response->print(""); + } + response->print( "" "" "

Heidelberg Phase Switch

");