Update xdrv_01_webserver.ino

Fix webpage redirect
This commit is contained in:
Theo Arends 2019-03-04 12:36:44 +01:00
parent 968719cea4
commit 3e1e565dff

View File

@ -84,7 +84,7 @@ const char HTTP_SCRIPT_ROOT[] PROGMEM =
"eb('l1').innerHTML=s;" "eb('l1').innerHTML=s;"
"}" "}"
"};" "};"
"x.open('GET','?m=1'+a,true);" // ?m related to WebServer->hasArg("m") "x.open('GET','.?m=1'+a,true);" // ?m related to WebServer->hasArg("m")
"x.send();" "x.send();"
"lt=setTimeout(la,{a});" // Settings.web_refresh "lt=setTimeout(la,{a});" // Settings.web_refresh
"}" "}"
@ -103,13 +103,11 @@ const char HTTP_SCRIPT_WIFI[] PROGMEM =
"}"; "}";
const char HTTP_SCRIPT_RELOAD[] PROGMEM = const char HTTP_SCRIPT_RELOAD[] PROGMEM =
"setTimeout(function(){location.href='.';}," STR(HTTP_RESTART_RECONNECT_TIME) ");" "setTimeout(function(){location.href='.';}," STR(HTTP_RESTART_RECONNECT_TIME) ");";
"</script>";
// Local OTA upgrade requires more time to complete cp: before web ui should be reloaded // Local OTA upgrade requires more time to complete cp: before web ui should be reloaded
const char HTTP_SCRIPT_RELOAD_OTA[] PROGMEM = const char HTTP_SCRIPT_RELOAD_OTA[] PROGMEM =
"setTimeout(function(){location.href='.';}," STR(HTTP_OTA_RESTART_RECONNECT_TIME) ");" "setTimeout(function(){location.href='.';}," STR(HTTP_OTA_RESTART_RECONNECT_TIME) ");";
"</script>";
const char HTTP_SCRIPT_CONSOL[] PROGMEM = const char HTTP_SCRIPT_CONSOL[] PROGMEM =
"var sn=0;" // Scroll position "var sn=0;" // Scroll position
@ -661,6 +659,7 @@ void WebRestart(uint8_t type)
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_RESTART); AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_RESTART);
String page = FPSTR(HTTP_HEAD); String page = FPSTR(HTTP_HEAD);
page += FPSTR(HTTP_SCRIPT_RELOAD);
page += FPSTR(HTTP_HEAD_STYLE); page += FPSTR(HTTP_HEAD_STYLE);
if (type) { if (type) {
@ -683,7 +682,6 @@ void WebRestart(uint8_t type)
} else { } else {
page += FPSTR(HTTP_BTN_MAIN); page += FPSTR(HTTP_BTN_MAIN);
} }
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_RELOAD));
ShowPage(page, !reset_only); ShowPage(page, !reset_only);
ShowWebSource(SRC_WEBGUI); ShowWebSource(SRC_WEBGUI);
@ -1705,11 +1703,11 @@ void HandleUpgradeFirmwareStart(void)
String page = FPSTR(HTTP_HEAD); String page = FPSTR(HTTP_HEAD);
page.replace(F("{v}"), FPSTR(S_INFORMATION)); page.replace(F("{v}"), FPSTR(S_INFORMATION));
page += FPSTR(HTTP_SCRIPT_RELOAD_OTA);
page += FPSTR(HTTP_HEAD_STYLE); page += FPSTR(HTTP_HEAD_STYLE);
page += F("<div style='text-align:center;'><b>" D_UPGRADE_STARTED " ...</b></div>"); page += F("<div style='text-align:center;'><b>" D_UPGRADE_STARTED " ...</b></div>");
page += FPSTR(HTTP_MSG_RSTRT); page += FPSTR(HTTP_MSG_RSTRT);
page += FPSTR(HTTP_BTN_MAIN); page += FPSTR(HTTP_BTN_MAIN);
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_RELOAD_OTA));
ShowPage(page); ShowPage(page);
snprintf_P(command, sizeof(command), PSTR(D_CMND_UPGRADE " 1")); snprintf_P(command, sizeof(command), PSTR(D_CMND_UPGRADE " 1"));
@ -1730,6 +1728,9 @@ void HandleUploadDone(void)
String page = FPSTR(HTTP_HEAD); String page = FPSTR(HTTP_HEAD);
page.replace(F("{v}"), FPSTR(S_INFORMATION)); page.replace(F("{v}"), FPSTR(S_INFORMATION));
if (!upload_error) {
page += FPSTR(HTTP_SCRIPT_RELOAD_OTA); // Refesh main web ui after OTA upgrade
}
page += FPSTR(HTTP_HEAD_STYLE); page += FPSTR(HTTP_HEAD_STYLE);
page += F("<div style='text-align:center;'><b>" D_UPLOAD " <font color='"); page += F("<div style='text-align:center;'><b>" D_UPLOAD " <font color='");
if (upload_error) { if (upload_error) {
@ -1750,7 +1751,6 @@ void HandleUploadDone(void)
} else { } else {
page += F("green'>" D_SUCCESSFUL "</font></b><br/>"); page += F("green'>" D_SUCCESSFUL "</font></b><br/>");
page += FPSTR(HTTP_MSG_RSTRT); page += FPSTR(HTTP_MSG_RSTRT);
page.replace(F("</script>"), FPSTR(HTTP_SCRIPT_RELOAD_OTA)); // Refesh main web ui after OTA upgrade
ShowWebSource(SRC_WEBGUI); ShowWebSource(SRC_WEBGUI);
restart_flag = 2; // Always restart to re-enable disabled features during update restart_flag = 2; // Always restart to re-enable disabled features during update
} }