From 6186959d8f403e40b6eb06a85038ee10bedc8591 Mon Sep 17 00:00:00 2001 From: Tobias Maier Date: Sat, 15 Feb 2025 17:06:20 +0100 Subject: [PATCH] First version able to OTA update --- lib/fetchOTA/fetchOTA.h | 2 +- src/global_data/defines.h | 2 +- src/main.cpp | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/fetchOTA/fetchOTA.h b/lib/fetchOTA/fetchOTA.h index 1d635c3..2a9312b 100644 --- a/lib/fetchOTA/fetchOTA.h +++ b/lib/fetchOTA/fetchOTA.h @@ -15,6 +15,7 @@ class OTA { Firmware getLatestVersionOnServer(); bool checkForUpdate(); + void run_ota_update(String url, std::function callback_started, std::function callback_finished, std::function callback_progress, std::function callback_error); private: bool _isHTTPS = false; @@ -22,7 +23,6 @@ class OTA { Version _currentVersion; String _current_device_configuration; Firmware createErrorResponse(const String& errorMsg); - void run_ota_update(String url, std::function callback_started, std::function callback_finished, std::function callback_progress, std::function callback_error); void update_started(); void update_finished(); void update_progress(int cur, int total); diff --git a/src/global_data/defines.h b/src/global_data/defines.h index 6ef85db..28b19d8 100644 --- a/src/global_data/defines.h +++ b/src/global_data/defines.h @@ -7,6 +7,6 @@ #define water_level_min_key "water_level_min" #define water_level_max_key "water_level_max" #define water_volume_key "water_volume" -#define current_software_version Version{0, 0, 3} +#define current_software_version Version{0, 0, 4} #define RESISTOR_VALUE 4 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 7028fd9..d2736eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,21 @@ extern "C" int rom_phy_get_vdd33(); AsyncWebServer server(80); #define FORMAT_LITTLEFS_IF_FAILED true +void update_started() { + Log.verbose("OTA Update started"); +} +void update_finished() { + Log.verbose("OTA Update finished"); +} + +void update_progress(int cur, int total) { + Log.verbose("OTA Update progress: %d/%d", cur, total); +} + +void update_error(int err) { + Log.error("OTA Update error: %d", err); +} void run_ota(void* parameter) { @@ -45,10 +59,12 @@ AsyncWebServer server(80); Firmware fw = ota.getLatestVersionOnServer(); Log.verbose("we are done"); Serial.printf("Firmware Info: Valid: %d, Version: %d.%d.%d, URL: %s\n", fw.valid, fw.version.major, fw.version.minor, fw.version.patch, fw.url.c_str()); - + ota.run_ota_update(fw.url, update_started, update_finished, update_progress, update_error); vTaskDelete(NULL); } + + void setup() { prefs.begin("waterlevel", false);