fix #123 - No autoforward after initiated update
This commit is contained in:
14
Ota.cpp
14
Ota.cpp
@@ -26,8 +26,7 @@ void Ota::updateFirmware(uint8_t* buf, size_t size)
|
||||
Log->println("EndOTA");
|
||||
if (ESP_OK == esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)))
|
||||
{
|
||||
delay(2000);
|
||||
restartEsp(RestartReason::OTACompleted);
|
||||
_updateCompleted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -40,3 +39,14 @@ bool Ota::updateStarted()
|
||||
{
|
||||
return _updateStarted;
|
||||
}
|
||||
|
||||
bool Ota::updateCompleted()
|
||||
{
|
||||
return _updateCompleted;
|
||||
}
|
||||
|
||||
bool Ota::restart()
|
||||
{
|
||||
_updateCompleted = false;
|
||||
_updateStarted = false;
|
||||
}
|
||||
|
||||
3
Ota.h
3
Ota.h
@@ -10,8 +10,11 @@ public:
|
||||
void updateFirmware(uint8_t* buf, size_t size);
|
||||
|
||||
bool updateStarted();
|
||||
bool updateCompleted();
|
||||
void restart();
|
||||
|
||||
private:
|
||||
bool _updateStarted = false;
|
||||
bool _updateCompleted = false;
|
||||
esp_ota_handle_t otaHandler = 0;
|
||||
};
|
||||
|
||||
@@ -157,7 +157,7 @@ void WebCfgServer::initialize()
|
||||
return _server.requestAuthentication();
|
||||
}
|
||||
String response = "";
|
||||
buildOtaHtml(response);
|
||||
buildOtaHtml(response, _server.arg("errored") != "");
|
||||
_server.send(200, "text/html", response);
|
||||
});
|
||||
_server.on("/uploadota", HTTP_POST, [&]() {
|
||||
@@ -165,7 +165,17 @@ void WebCfgServer::initialize()
|
||||
return _server.requestAuthentication();
|
||||
}
|
||||
|
||||
_server.send(200, "text/html", "");
|
||||
if (_ota->updateStarted() && _ota->updateCompleted()) {
|
||||
String response = "";
|
||||
buildOtaCompletedHtml(response);
|
||||
_server.send(200, "text/html", response);
|
||||
delay(2000);
|
||||
restartEsp(RestartReason::OTACompleted);
|
||||
} else {
|
||||
ota->restart();
|
||||
_server.sendHeader("Location", "/ota?errored=true");
|
||||
_server.send(302, "text/plain", "");
|
||||
}
|
||||
}, [&]() {
|
||||
if (_hasCredentials && !_server.authenticate(_credUser, _credPassword)) {
|
||||
return _server.requestAuthentication();
|
||||
@@ -639,7 +649,7 @@ void WebCfgServer::buildCredHtml(String &response)
|
||||
response.concat("</BODY></HTML>");
|
||||
}
|
||||
|
||||
void WebCfgServer::buildOtaHtml(String &response)
|
||||
void WebCfgServer::buildOtaHtml(String &response, bool errored)
|
||||
{
|
||||
buildHtmlHeader(response);
|
||||
|
||||
@@ -650,6 +660,10 @@ void WebCfgServer::buildOtaHtml(String &response)
|
||||
return;
|
||||
}
|
||||
|
||||
if (errored) {
|
||||
response.concat("<div>Over-the-air update errored. Please check the logs for more info</div><br/>");
|
||||
}
|
||||
|
||||
response.concat("<form id=\"upform\" enctype=\"multipart/form-data\" action=\"/uploadota\" method=\"POST\"><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"100000\" />Choose the updated nuki_hub.bin file to upload: <input name=\"uploadedfile\" type=\"file\" accept=\".bin\" /><br/>");
|
||||
response.concat("<br><input id=\"submitbtn\" type=\"submit\" value=\"Upload File\" /></form>");
|
||||
response.concat("<div id=\"msgdiv\" style=\"visibility:hidden\">Initiating Over-the-air update. This will take about two minutes, please be patient.<br>You will be forwarded automatically when the update is complete.</div>");
|
||||
@@ -660,13 +674,25 @@ void WebCfgServer::buildOtaHtml(String &response)
|
||||
response.concat(" function hideshow() {");
|
||||
response.concat(" document.getElementById('upform').style.visibility = 'hidden';");
|
||||
response.concat(" document.getElementById('msgdiv').style.visibility = 'visible';");
|
||||
response.concat(" setTimeout(\"location.href = '/';\",120000);");
|
||||
response.concat(" }");
|
||||
response.concat("});");
|
||||
response.concat("</script>");
|
||||
response.concat("</BODY></HTML>");
|
||||
}
|
||||
|
||||
void WebCfgServer::buildOtaCompletedHtml(String &response)
|
||||
{
|
||||
buildHtmlHeader(response);
|
||||
|
||||
response.concat("<div>Over-the-air update completed.<br>You will be forwarded automatically.</div>");
|
||||
response.concat("<script type=\"text/javascript\">");
|
||||
response.concat("window.addEventListener('load', function () {");
|
||||
response.concat(" setTimeout(\"location.href = '/';\",10000);");
|
||||
response.concat("});");
|
||||
response.concat("</script>");
|
||||
response.concat("</BODY></HTML>");
|
||||
}
|
||||
|
||||
void WebCfgServer::buildMqttConfigHtml(String &response)
|
||||
{
|
||||
buildHtmlHeader(response);
|
||||
|
||||
@@ -36,7 +36,8 @@ private:
|
||||
bool processArgs(String& message);
|
||||
void buildHtml(String& response);
|
||||
void buildCredHtml(String& response);
|
||||
void buildOtaHtml(String& response);
|
||||
void buildOtaHtml(String& response, bool errored);
|
||||
void buildOtaCompletedHtml(String& response);
|
||||
void buildMqttConfigHtml(String& response);
|
||||
void buildNukiConfigHtml(String& response);
|
||||
void buildConfirmHtml(String& response, const String &message, uint32_t redirectDelay = 5);
|
||||
|
||||
Reference in New Issue
Block a user