From 6e171fbde74077118152bd3c13173ec1d25f3489 Mon Sep 17 00:00:00 2001 From: tobimai Date: Sat, 22 Feb 2025 22:15:43 +0100 Subject: [PATCH] Version bumps, OTA working --- data/logic.js | 2 +- data/update_progress.html | 19 ++++++++++++++++++- data/version | 2 +- src/global_data/defines.h | 2 +- src/tools/tools.cpp | 4 +++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/data/logic.js b/data/logic.js index 527a9e5..3125deb 100644 --- a/data/logic.js +++ b/data/logic.js @@ -54,7 +54,7 @@ function fetchUpdateData(gauge) { .then(data => { document.getElementById('current_fw').textContent = data.current_version || 'N/A'; document.getElementById('server_fw').textContent = data.new_version || 'N/A'; - if (data.update_available == "true") { + if (data.update_available == true) { document.getElementById("update_button").style.visibility = 'visible'; } else { document.getElementById("update_button").style.visibility = 'hidden'; diff --git a/data/update_progress.html b/data/update_progress.html index 5bd38db..bf06747 100644 --- a/data/update_progress.html +++ b/data/update_progress.html @@ -28,7 +28,24 @@ console.log('Progress:', event.data); // Update the progress bar let progress = parseInt(event.data); - document.getElementById('progress').textContent = progress + '%'; + if (progress == -1) { + document.getElementById('progress').textContent = "Upgrade Done, wait for reboot..."; + + const checkStatus = setInterval(() => { + fetch('/ota_udpate_status') + .then(response => { + if (response.ok) { + clearInterval(checkStatus); + window.location.href = '/'; + } + }) + .catch(error => console.error('Error checking OTA update status:', error)); + }, 1000); + } else { + document.getElementById('progress').textContent = progress + '%'; + } + + }; ws.onerror = function(error) { diff --git a/data/version b/data/version index e440e5c..bf0d87a 100644 --- a/data/version +++ b/data/version @@ -1 +1 @@ -3 \ No newline at end of file +4 \ No newline at end of file diff --git a/src/global_data/defines.h b/src/global_data/defines.h index 51713e7..eeddaa8 100644 --- a/src/global_data/defines.h +++ b/src/global_data/defines.h @@ -8,6 +8,6 @@ #define water_level_max_key "water_level_max" #define water_volume_key "water_volume" #define current_software_version Version{0, 0, 16} -#define REQUIRED_SPIFFS_VERSION Version{3, 0, 0} +#define REQUIRED_SPIFFS_VERSION Version{4, 0, 0} #define RESISTOR_VALUE 4 \ No newline at end of file diff --git a/src/tools/tools.cpp b/src/tools/tools.cpp index 526b9ad..14f61db 100644 --- a/src/tools/tools.cpp +++ b/src/tools/tools.cpp @@ -54,12 +54,14 @@ void update_started() { void update_finished() { Log.verbose("OTA Update finished"); ota_status.update_progress = -1; + ws.textAll(String(-1).c_str()); } void update_progress(int cur, int total) { ota_status.update_progress = 0; if (cur != 0 ) { - ota_status.update_progress = total/cur; + ota_status.update_progress = int(float(cur)/float(total)*100); + Log.verbose("OTA Update progress: %d/%d, %i", cur, total, ota_status.update_progress); } ws.textAll(String(ota_status.update_progress).c_str()); Log.verbose("OTA Update progress: %d/%d", cur, total);