fix ota upload
All checks were successful
Compilie project and upload binaries / test (push) Successful in 3m59s

This commit is contained in:
2025-11-05 22:08:42 +01:00
parent 53920dbb77
commit 3dc339c449
8 changed files with 84 additions and 31 deletions

View File

@@ -49,4 +49,4 @@ jobs:
curl -X PUT \ curl -X PUT \
-H "Content-Type: application/octet-stream" \ -H "Content-Type: application/octet-stream" \
--data-binary @.pio/build/ESP32_INA233/littlefs.bin \ --data-binary @.pio/build/ESP32_INA233/littlefs.bin \
https://iot.tobiasmaier.me/filesystem/waterlevel/generic/${VERSION} https://iot.tobiasmaier.me/filesystem/waterlevel/generic/${VERSION}.0.0

49
.vscode/settings.json vendored
View File

@@ -22,6 +22,53 @@
"text_encoding": "cpp", "text_encoding": "cpp",
"thread": "cpp", "thread": "cpp",
"*.inc": "cpp", "*.inc": "cpp",
"cstddef": "cpp" "cstddef": "cpp",
"iomanip": "cpp",
"sstream": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"map": "cpp",
"set": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory_resource": "cpp",
"netfwd": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ratio": "cpp",
"source_location": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"iosfwd": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"semaphore": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
} }
} }

View File

@@ -49,7 +49,7 @@ function fetchWaterData(gauge) {
} }
function fetchUpdateData(gauge) { function fetchUpdateData(gauge) {
const apiUrl = '/ota_udpate_status'; const apiUrl = '/ota_update_status';
// Fetching data from the API // Fetching data from the API
fetch(apiUrl) fetch(apiUrl)
.then(response => response.json()) .then(response => response.json())

View File

@@ -5,20 +5,8 @@
</head> </head>
<body> <body>
<div class="container"> <script>
<div class="card bd-success"> const webSocket = new WebSocket('ws://' + window.location.host + '/webSocket');
<header class="is-center">
<h4>Update running</h4>
</header>
<div class="is-center" id="progress">
Running update...
</div>
</div>
</div>
</body>
<script>
const webSocket = new WebSocket('webSocket://' + window.location.host + '/webSocket');
webSocket.onopen = function() { webSocket.onopen = function() {
console.log('WebSocket connection opened.'); console.log('WebSocket connection opened.');
@@ -32,7 +20,7 @@
document.getElementById('progress').textContent = "Upgrade Done, wait for reboot..."; document.getElementById('progress').textContent = "Upgrade Done, wait for reboot...";
const checkStatus = setInterval(() => { const checkStatus = setInterval(() => {
fetch('/ota_udpate_status') fetch('/ota_update_status')
.then(response => { .then(response => {
if (response.ok) { if (response.ok) {
clearInterval(checkStatus); clearInterval(checkStatus);
@@ -55,4 +43,16 @@
webSocket.onclose = function() { webSocket.onclose = function() {
console.log('WebSocket connection closed.'); console.log('WebSocket connection closed.');
}; };
</script> </script>
<div class="container">
<div class="card bd-success">
<header class="is-center">
<h4>Update running</h4>
</header>
<div class="is-center" id="progress">
Running update...
</div>
</div>
</div>
</body>

View File

@@ -90,6 +90,7 @@ Firmware OTA::createErrorResponse(const String& errorMsg) {
void run_ota_update(String url, std::function<void()> callback_started, std::function<void()> callback_finished, std::function<void(int, int)> callback_progress, std::function<void(int)> callback_error) { void run_ota_update(String url, std::function<void()> callback_started, std::function<void()> callback_finished, std::function<void(int, int)> callback_progress, std::function<void(int)> callback_error) {
Logger.log(0, ELOG_LEVEL_DEBUG, "Starting OTA upgrade"); Logger.log(0, ELOG_LEVEL_DEBUG, "Starting OTA upgrade");
Logger.log(0, ELOG_LEVEL_DEBUG, "URL: %s", url);
HTTPUpdate httpUpdate; HTTPUpdate httpUpdate;
httpUpdate.onStart(callback_started); httpUpdate.onStart(callback_started);
httpUpdate.onEnd(callback_finished); httpUpdate.onEnd(callback_finished);
@@ -101,13 +102,14 @@ void run_ota_update(String url, std::function<void()> callback_started, std::fu
if (url.startsWith("https")) { if (url.startsWith("https")) {
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL"); Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL");
WiFiClient client; HTTPClient http_client;
// client.setInsecure(); http_client.begin(url);
ret = httpUpdate.update(client, url); ret = httpUpdate.update(http_client, url);
} else if (url.startsWith("http")) { } else if (url.startsWith("http")) {
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTP URL"); Logger.log(0, ELOG_LEVEL_DEBUG, "HTTP URL");
WiFiClient client; HTTPClient http_client;
ret = httpUpdate.update(client, url); http_client.begin(url);
ret = httpUpdate.update(http_client, url);
} else { } else {
Logger.log(0, ELOG_LEVEL_ERROR, "URL is not valid: \n%s", url.c_str()); Logger.log(0, ELOG_LEVEL_ERROR, "URL is not valid: \n%s", url.c_str());
} }
@@ -140,13 +142,15 @@ void run_ota_spiffs_update(String url, std::function<void()> callback_started,
if (url.startsWith("https")) { if (url.startsWith("https")) {
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL"); Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL");
WiFiClient client; HTTPClient http_client;
http_client.begin(url);
// client.setInsecure(); // client.setInsecure();
ret = httpUpdate.updateSpiffs(client, url); ret = httpUpdate.updateSpiffs(http_client, url);
} else if (url.startsWith("http")) { } else if (url.startsWith("http")) {
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTP URL"); Logger.log(0, ELOG_LEVEL_DEBUG, "HTTP URL");
WiFiClient client; HTTPClient http_client;
ret = httpUpdate.updateSpiffs(client, url); http_client.begin(url);
ret = httpUpdate.updateSpiffs(http_client, url);
} else { } else {
Logger.log(0, ELOG_LEVEL_ERROR, "URL is not valid: \n%s", url.c_str()); Logger.log(0, ELOG_LEVEL_ERROR, "URL is not valid: \n%s", url.c_str());
} }

View File

@@ -7,7 +7,7 @@
#define water_level_min_key "water_level_min" #define water_level_min_key "water_level_min"
#define water_level_max_key "water_level_max" #define water_level_max_key "water_level_max"
#define water_volume_key "water_volume" #define water_volume_key "water_volume"
#define current_software_version Version{2, 2, 0} #define current_software_version Version{2, 3, 0}
#define REQUIRED_SPIFFS_VERSION Version{9, 0, 0} #define REQUIRED_SPIFFS_VERSION Version{9, 0, 0}
#define RESISTOR_VALUE 4 #define RESISTOR_VALUE 4

View File

@@ -51,7 +51,7 @@ void setup_api_endpoints(){
request->send(200, "application/json", output); request->send(200, "application/json", output);
}); });
server.on("/ota_udpate_status", HTTP_GET, [](AsyncWebServerRequest* request) { server.on("/ota_update_status", HTTP_GET, [](AsyncWebServerRequest* request) {
String output; String output;
serializeJson(build_ota_json(ota_status), output); serializeJson(build_ota_json(ota_status), output);
request->send(200, "application/json", output); request->send(200, "application/json", output);

View File

@@ -155,7 +155,9 @@ bool check_for_internet_connection() {
void run_ota_update_task(void* parameter) { void run_ota_update_task(void* parameter) {
TaskArgs_t *args = (TaskArgs_t *) parameter; TaskArgs_t *args = (TaskArgs_t *) parameter;
LOG(ELOG_LEVEL_DEBUG, "Running OTA upgrade now with URL: %s", args->ota_status.update_url.c_str()); LOG(ELOG_LEVEL_DEBUG, "Running OTA upgrade now with URL: %s", args->ota_status.update_url.c_str());
run_ota_update(args->ota_status.update_url, update_started, update_finished, update_progress, update_error); String ota_url = args->ota_status.update_url;
Serial.println(ota_url);
run_ota_update(ota_url, update_started, update_finished, update_progress, update_error);
vTaskDelete(NULL); vTaskDelete(NULL);
} }