Skip to content

Commit

Permalink
redirect to start after configuration saved
Browse files Browse the repository at this point in the history
  • Loading branch information
technyon committed Apr 4, 2022
1 parent 3cac2c5 commit 8568e23
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
38 changes: 32 additions & 6 deletions WebCfgServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -240,6 +252,20 @@ void WebCfgServer::buildCredHtml(String &response)
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,
const char *token,
Expand Down
3 changes: 2 additions & 1 deletion WebCfgServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 8568e23

Please sign in to comment.