diff --git a/.gitea/workflows/on_push.yaml b/.gitea/workflows/on_push.yaml index af20cbf..65b0d5a 100644 --- a/.gitea/workflows/on_push.yaml +++ b/.gitea/workflows/on_push.yaml @@ -25,7 +25,8 @@ jobs: run: ls -lah .pio/build/ESP32_INA233/ .pio/build/ESP32_INA226/ - name: Upload firmware binary for INA233 run: | - VERSION=$(cat version) + VERSION=$(sed -n 's/#define current_version Version{[[:space:]]*\([0-9]\+\),[[:space:]]*\([0-9]\+\),[[:space:]]*\([0-9]\+\)}/\1.\2.\3/p' src/global_data/defines.h) + echo "Extracted version: $VERSION" curl -X PUT \ -H "Content-Type: application/octet-stream" \ @@ -34,7 +35,8 @@ jobs: - name: Upload firmware binary for INA226 run: | - VERSION=$(cat version) + VERSION=$(sed -n 's/#define current_version Version{[[:space:]]*\([0-9]\+\),[[:space:]]*\([0-9]\+\),[[:space:]]*\([0-9]\+\)}/\1.\2.\3/p' src/global_data/defines.h) + echo "Extracted version: $VERSION" curl -X PUT \ -H "Content-Type: application/octet-stream" \ diff --git a/lib/fetchOTA/fetchOTA.cpp b/lib/fetchOTA/fetchOTA.cpp index 9c03fad..b23d8fa 100644 --- a/lib/fetchOTA/fetchOTA.cpp +++ b/lib/fetchOTA/fetchOTA.cpp @@ -7,6 +7,8 @@ #include #include +#include +#include OTA::OTA(String server_url, String currentVersion, String currentDeviceConfiguration) { @@ -71,6 +73,36 @@ Firmware OTA::createErrorResponse(const String& errorMsg) { }; } +void OTA::run_ota_update(String url) { + Log.verbose("Starting OTA upgrade"); + HTTPUpdate httpUpdate; + httpUpdate.onStart(update_started); + httpUpdate.onEnd(update_finished); + httpUpdate.onProgress(update_progress); + httpUpdate.onError(update_error); + Serial.println("RUNNING OTA"); + + WiFiClientSecure client; + client.setInsecure(); + + t_httpUpdate_return ret = httpUpdate.update(client, "https://iot.tobiasmaier.me/firmware/waterlevel/INA233/1_1_1.bin"); + // t_httpUpdate_return ret = httpUpdate.update(client, "https://iot.tobiasmaier.me", 443, "/firmware/waterlevel/INA233/1_0_1.bin"); + + switch (ret) { + case HTTP_UPDATE_FAILED: + Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); + break; + + case HTTP_UPDATE_NO_UPDATES: + Serial.println("HTTP_UPDATE_NO_UPDATES"); + break; + + case HTTP_UPDATE_OK: + Serial.println("HTTP_UPDATE_OK"); + break; + } +} + #endif \ No newline at end of file diff --git a/src/global_data/defines.h b/src/global_data/defines.h index 42c3a95..c576e37 100644 --- a/src/global_data/defines.h +++ b/src/global_data/defines.h @@ -5,5 +5,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_version Version{0, 0, 2} #define RESISTOR_VALUE 4 \ No newline at end of file diff --git a/src/global_data/global_data.h b/src/global_data/global_data.h index 7bab410..4201337 100644 --- a/src/global_data/global_data.h +++ b/src/global_data/global_data.h @@ -1,4 +1,5 @@ #include +#include #pragma once @@ -37,4 +38,11 @@ struct ActiveErrors { bool current_high; bool level_low; bool level_high; +}; + +struct OTAStatus { + bool update_available; + Version current_version; + Version latest_version; + int update_progress; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 6b09bd9..4aba952 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,33 +59,7 @@ void update_started() { 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()); - // Serial.println("RUNNING OTA"); - // // WiFiClient client; - // httpUpdate.onStart(update_started); - // httpUpdate.onEnd(update_finished); - // httpUpdate.onProgress(update_progress); - // httpUpdate.onError(update_error); - // Serial.println("RUNNING OTA"); - // WiFiClientSecure client; - // client.setInsecure(); - - // t_httpUpdate_return ret = httpUpdate.update(client, "https://iot.tobiasmaier.me/firmware/waterlevel/INA233/1_1_1.bin"); - // // t_httpUpdate_return ret = httpUpdate.update(client, "https://iot.tobiasmaier.me", 443, "/firmware/waterlevel/INA233/1_0_1.bin"); - - // switch (ret) { - // case HTTP_UPDATE_FAILED: - // Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); - // break; - - // case HTTP_UPDATE_NO_UPDATES: - // Serial.println("HTTP_UPDATE_NO_UPDATES"); - // break; - - // case HTTP_UPDATE_OK: - // Serial.println("HTTP_UPDATE_OK"); - // break; - // } vTaskDelete(NULL); } diff --git a/version b/version deleted file mode 100644 index 8a9ecc2..0000000 --- a/version +++ /dev/null @@ -1 +0,0 @@ -0.0.1 \ No newline at end of file