From 8568e237cc777c7123dd841d7aa2fdb11eb4e3d1 Mon Sep 17 00:00:00 2001 From: technyon Date: Mon, 4 Apr 2022 22:29:13 +0200 Subject: [PATCH] redirect to start after configuration saved --- WebCfgServer.cpp | 38 ++++++++++++++++++++++++++++++++------ WebCfgServer.h | 3 ++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index da8310dd..76420df9 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -48,14 +48,27 @@ void WebCfgServer::initialize() if (_hasCredentials && !server.authenticate(_credUser, _credPassword)) { return server.requestAuthentication(); } - processArgs(); - server.send(200, "text/plain", "Configuration saved ... restarting."); + bool configChanged = processArgs(); + if(configChanged) + { + String response = ""; + buildConfirmHtml(response); + server.send(200, "text/html", response); + Serial.println(F("Restarting")); + unsigned long timeout = millis() + 1000; + while(millis() < timeout) + { + server.handleClient(); + delay(10); + } + ESP.restart(); + } }); server.begin(); } -void WebCfgServer::processArgs() +bool WebCfgServer::processArgs() { bool configChanged = false; bool clearMqttCredentials = false; @@ -153,10 +166,9 @@ void WebCfgServer::processArgs() { _enabled = false; _preferences->end(); - Serial.println(F("Restarting")); - vTaskDelay( 200 / portTICK_PERIOD_MS); - ESP.restart(); } + + return configChanged; } void WebCfgServer::update() @@ -240,6 +252,20 @@ void WebCfgServer::buildCredHtml(String &response) response.concat("\n"); } +void WebCfgServer::buildConfirmHtml(String &response) +{ + response.concat("\n"); + response.concat("\n"); + response.concat("NUKI Hub\n"); + response.concat(""); + response.concat("\n\n"); + response.concat("\n"); + + response.concat("Configuration saved ... restarting.\n"); + + response.concat("\n"); + response.concat("\n"); +} void WebCfgServer::printInputField(String& response, const char *token, diff --git a/WebCfgServer.h b/WebCfgServer.h index de10f35c..4b94836b 100644 --- a/WebCfgServer.h +++ b/WebCfgServer.h @@ -28,9 +28,10 @@ class WebCfgServer private: - void processArgs(); + bool processArgs(); void buildHtml(String& response); void buildCredHtml(String& response); + void buildConfirmHtml(String& response); void printInputField(String& response, const char* token, const char* description, const char* value, size_t maxLength); void printInputField(String& response, const char* token, const char* description, const int value, size_t maxLength);