From fc6213f1d67b514566cf5783779fdfe6a06317f3 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 24 Sep 2024 10:43:39 +1000 Subject: [PATCH] Smoother update progression --- src/main.cpp | 7 ++++--- src/static/static_js.cpp | 2 +- src/static/static_js.js | 11 +++++++++-- src/updater.cpp | 12 ++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fadb897..17ea471 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,7 @@ void setup() initBLE(); initWiFi(); - delay(1000); + delay(500); Serial.println("Connection Type: " + String(config.getUChar("connection_type"))); if( (config.getUChar("connection_type") == CONNECTION_TYPE_TUNERSTUDIO) ) @@ -67,9 +67,10 @@ void setup() //Updates the firmware AND data from remote URLs server.on(UPDATE_REMOTE_URL, HTTP_POST, [](AsyncWebServerRequest *request) { + request->onDisconnect([](){ + ESP.restart(); + }); request->send(200, "text/html", saveRemoteFW_URLs(request)); - delay(1000); //Wait 1 second to allow the page to be sent before restarting - ESP.restart(); }); //Scan the wifi networks and return them as JSON server.on("/wifi", HTTP_GET, [](AsyncWebServerRequest *request) { diff --git a/src/static/static_js.cpp b/src/static/static_js.cpp index b0d59c5..d19bd8a 100644 --- a/src/static/static_js.cpp +++ b/src/static/static_js.cpp @@ -4,7 +4,7 @@ String staticJS_updates() { String js = ""; js += ""; return js; diff --git a/src/static/static_js.js b/src/static/static_js.js index f8b4d17..0a2e30d 100644 --- a/src/static/static_js.js +++ b/src/static/static_js.js @@ -96,8 +96,15 @@ function updateProgress() const percentComplete = Math.floor((jsonData.updateProgress / jsonData.updateSize) * 100) setInnerHTML(getElementByID('updatePercent'), percentComplete) console.log(percentComplete) - if(percentComplete >= 98) { window.location.href = '/' } + if(percentComplete >= 98) + { + setTimeout(() => { + const wl = window.location + wl.href = '/' + wl=wl.href //Force a refresh of page without resending POST data + }, 7000) + } else { updateProgress() } } - }, 1500); + }, 1100); } \ No newline at end of file diff --git a/src/updater.cpp b/src/updater.cpp index 200f5c8..1eeaf94 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -110,12 +110,12 @@ String updateInProgressPage() updatePage += "
"; updatePage += "
"; - updatePage += "Current Status: Preparing to update
"; - updatePage += "Current Progress:
"; - updatePage += "Update Size:
"; - updatePage += "Update Completion: %
"; + updatePage += "Current Status: Preparing to update
"; + updatePage += "Update Size:
"; + updatePage += "Downloaded:
"; + updatePage += "Update Completion: %
"; - updatePage += "
"; + updatePage += "
"; return updatePage; } @@ -193,7 +193,7 @@ void updateFromRemote() case HTTP_UPDATE_OK: Serial.println("HTTP_UPDATE_OK"); config.putString("newData_url", ""); - delay(500); + delay(1300); //Need to wait at least 1 update cycle (1100ms) so that the frontend knows the update is complete ESP.restart(); break; }