From 83ed0ebf42da34d484ed7cc77a8988c2310676c5 Mon Sep 17 00:00:00 2001 From: Dennis960 <66166638+Dennis960@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:32:47 +0200 Subject: [PATCH] Fix sensor ota update percentage --- Firmware/frontend/src/pages/update-page.ts | 16 +++++++--------- Firmware/main/configuration_mode_server.c | 9 ++++++++- Firmware/main/configuration_mode_server.h | 2 +- Firmware/main/main.c | 6 +++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Firmware/frontend/src/pages/update-page.ts b/Firmware/frontend/src/pages/update-page.ts index 10c85f0..59746af 100644 --- a/Firmware/frontend/src/pages/update-page.ts +++ b/Firmware/frontend/src/pages/update-page.ts @@ -32,19 +32,17 @@ export class UpdatePage extends BasePage { this.firmwareUpdateProgress = 0; while (this.firmwareUpdateProgress !== null) { this.firmwareUpdateProgress = await getUpdatePercentage(); - if ( - this.firmwareUpdateProgress === 100 || - this.firmwareUpdateProgress === -1 - ) { + if (this.firmwareUpdateProgress === -1) { + this.infoText = "Es wurde noch kein Update gestartet"; + } else if (this.firmwareUpdateProgress === 100) { this.infoText = "Der Sensor wurde erfolgreich aktualisiert"; this.firmwareUpdateProgress = null; return; - } - if (this.firmwareUpdateProgress < 100) { + } else if (this.firmwareUpdateProgress < 100) { await new Promise((resolve) => setTimeout(resolve, 200)); - } - if (this.firmwareUpdateProgress > 80) { - this.infoText = "Der Sensor wird jetzt neu gestartet"; + if (this.firmwareUpdateProgress > 80) { + this.infoText = "Der Sensor wird jetzt neu gestartet"; + } } } } diff --git a/Firmware/main/configuration_mode_server.c b/Firmware/main/configuration_mode_server.c index 297e9b0..617070b 100644 --- a/Firmware/main/configuration_mode_server.c +++ b/Firmware/main/configuration_mode_server.c @@ -617,6 +617,7 @@ esp_err_t post_api_update_firmware_handler(httpd_req_t *req) } plantstore_setFirmwareUpdateUrl(url); + ota_update_percentage = 0; const char resp[] = "OK"; httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); @@ -893,7 +894,7 @@ void register_uri_handlers(httpd_handle_t server) httpd_register_uri_handler(server, &get); } -httpd_handle_t start_webserver(void) +httpd_handle_t start_webserver(bool resetReasonOta) { ESP_LOGI("HTTP", "Starting HTTP server"); /* Empty handle to esp_http_server */ @@ -904,6 +905,12 @@ httpd_handle_t start_webserver(void) config.uri_match_fn = httpd_uri_match_wildcard; config.max_uri_handlers = 50; + if (resetReasonOta) + { + ESP_LOGI("OTA", "Reset reason is OTA, so OTA finished successfully"); + ota_update_percentage = 100; + } + /* Start the httpd server */ ESP_ERROR_CHECK(httpd_start(&server, &config)); register_uri_handlers(server); diff --git a/Firmware/main/configuration_mode_server.h b/Firmware/main/configuration_mode_server.h index 1c8e543..a060b8f 100644 --- a/Firmware/main/configuration_mode_server.h +++ b/Firmware/main/configuration_mode_server.h @@ -3,6 +3,6 @@ #include "esp_http_server.h" /* Function for starting the webserver */ -httpd_handle_t start_webserver(void); +httpd_handle_t start_webserver(bool resetReasonOta); /* Function for stopping the webserver */ void stop_webserver(httpd_handle_t server); \ No newline at end of file diff --git a/Firmware/main/main.c b/Firmware/main/main.c index 1a854b3..b78d234 100644 --- a/Firmware/main/main.c +++ b/Firmware/main/main.c @@ -25,7 +25,7 @@ void start_deep_sleep() esp_deep_sleep(sleepTime); } -void configuration_mode(bool isConfigured) +void configuration_mode(bool isConfigured, bool resetReasonOta) { sensors_playStartupSound(); plantfi_setEnableNatAndDnsOnConnect(true); @@ -39,7 +39,7 @@ void configuration_mode(bool isConfigured) plantfi_configureAp("Blumy", "", 4, &userConnectedToAp); ESP_LOGI("MODE", "Starting webserver"); - httpd_handle_t webserver = start_webserver(); + httpd_handle_t webserver = start_webserver(resetReasonOta); plantfi_configureStaFromPlantstore(); bool wasBootButtonPressed = false; @@ -135,7 +135,7 @@ void app_main() if (isManualReset || !isConfigured) { - configuration_mode(isConfigured); + configuration_mode(isConfigured, resetReasonOta); } else {