redirect to start after configuration saved

This commit is contained in:
technyon
2022-04-04 22:29:13 +02:00
parent 3cac2c5de5
commit 8568e237cc
2 changed files with 34 additions and 7 deletions

View File

@@ -48,14 +48,27 @@ void WebCfgServer::initialize()
if (_hasCredentials && !server.authenticate(_credUser, _credPassword)) { if (_hasCredentials && !server.authenticate(_credUser, _credPassword)) {
return server.requestAuthentication(); return server.requestAuthentication();
} }
processArgs(); bool configChanged = processArgs();
server.send(200, "text/plain", "Configuration saved ... restarting."); 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(); server.begin();
} }
void WebCfgServer::processArgs() bool WebCfgServer::processArgs()
{ {
bool configChanged = false; bool configChanged = false;
bool clearMqttCredentials = false; bool clearMqttCredentials = false;
@@ -153,10 +166,9 @@ void WebCfgServer::processArgs()
{ {
_enabled = false; _enabled = false;
_preferences->end(); _preferences->end();
Serial.println(F("Restarting"));
vTaskDelay( 200 / portTICK_PERIOD_MS);
ESP.restart();
} }
return configChanged;
} }
void WebCfgServer::update() void WebCfgServer::update()
@@ -240,6 +252,20 @@ void WebCfgServer::buildCredHtml(String &response)
response.concat("</HTML>\n"); response.concat("</HTML>\n");
} }
void WebCfgServer::buildConfirmHtml(String &response)
{
response.concat("<HTML>\n");
response.concat("<HEAD>\n");
response.concat("<TITLE>NUKI Hub</TITLE>\n");
response.concat("<meta http-equiv=\"Refresh\" content=\"5; url=/\" />");
response.concat("\n</HEAD>\n");
response.concat("<BODY>\n");
response.concat("Configuration saved ... restarting.\n");
response.concat("</BODY>\n");
response.concat("</HTML>\n");
}
void WebCfgServer::printInputField(String& response, void WebCfgServer::printInputField(String& response,
const char *token, const char *token,

View File

@@ -28,9 +28,10 @@ public:
private: private:
void processArgs(); bool processArgs();
void buildHtml(String& response); void buildHtml(String& response);
void buildCredHtml(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 char* value, size_t maxLength);
void printInputField(String& response, const char* token, const char* description, const int value, size_t maxLength); void printInputField(String& response, const char* token, const char* description, const int value, size_t maxLength);