7 Commits

Author SHA1 Message Date
b68e775350 stuff
All checks were successful
Compilie project and upload binaries / test (push) Successful in 3m59s
2025-11-05 22:41:54 +01:00
7e30340e93 test
All checks were successful
Compilie project and upload binaries / test (push) Successful in 4m1s
2025-11-05 22:20:33 +01:00
3dc339c449 fix ota upload
All checks were successful
Compilie project and upload binaries / test (push) Successful in 3m59s
2025-11-05 22:08:42 +01:00
53920dbb77 Merge pull request 'rev2' (#4) from rev2 into main
All checks were successful
Compilie project and upload binaries / test (push) Successful in 4m1s
Reviewed-on: #4
2025-11-05 20:33:26 +01:00
dbb32efda8 Merge pull request 'rev2' (#3) from rev2 into main
All checks were successful
Compilie project and upload binaries / test (push) Successful in 3m57s
Reviewed-on: #3
2025-11-05 19:17:56 +01:00
7542d44e21 revert df06be23cb
Some checks failed
Test compiling project / test (push) Failing after 0s
revert Fix image pull URL
2025-11-05 19:17:49 +01:00
df06be23cb Fix image pull URL
Some checks failed
Test compiling project / test (push) Failing after 59s
2025-11-02 15:45:40 +01:00
11 changed files with 94 additions and 56 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

View File

@@ -1,6 +1,4 @@
{ {
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [ "recommendations": [
"pioarduino.pioarduino-ide", "pioarduino.pioarduino-ide",
"platformio.platformio-ide" "platformio.platformio-ide"

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);
@@ -56,3 +44,15 @@
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

@@ -6,7 +6,6 @@
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <WiFiClient.h> #include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <vector> #include <vector>
#include <Elog.h> #include <Elog.h>
#include <HTTPUpdate.h> #include <HTTPUpdate.h>
@@ -91,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);
@@ -98,33 +98,29 @@ void run_ota_update(String url, std::function<void()> callback_started, std::fu
httpUpdate.onError(callback_error); httpUpdate.onError(callback_error);
Logger.log(0, ELOG_LEVEL_DEBUG, "Defined callbacks, Starting update now"); Logger.log(0, ELOG_LEVEL_DEBUG, "Defined callbacks, Starting update now");
t_httpUpdate_return ret = HTTP_UPDATE_FAILED; t_httpUpdate_return ret;
if (url.startsWith("https")) { if (url.startsWith("https")) {
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL"); Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL");
WiFiClientSecure 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());
if (callback_error) callback_error(-1);
return;
} }
switch (ret) { switch (ret) {
case HTTP_UPDATE_FAILED: case HTTP_UPDATE_FAILED:
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
// Don't restart ESP on HTTP errors, just return
if (callback_error) callback_error(httpUpdate.getLastError());
break; break;
case HTTP_UPDATE_NO_UPDATES: case HTTP_UPDATE_NO_UPDATES:
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_NO_UPDATES"); Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_NO_UPDATES");
if (callback_error) callback_error(-2);
break; break;
case HTTP_UPDATE_OK: case HTTP_UPDATE_OK:
@@ -142,33 +138,30 @@ void run_ota_spiffs_update(String url, std::function<void()> callback_started,
httpUpdate.onError(callback_error); httpUpdate.onError(callback_error);
Logger.log(0, ELOG_LEVEL_DEBUG, "Defined callbacks, Starting update now"); Logger.log(0, ELOG_LEVEL_DEBUG, "Defined callbacks, Starting update now");
t_httpUpdate_return ret = HTTP_UPDATE_FAILED; t_httpUpdate_return ret;
if (url.startsWith("https")) { if (url.startsWith("https")) {
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL"); Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL");
WiFiClientSecure client; HTTPClient http_client;
client.setInsecure(); http_client.begin(url);
ret = httpUpdate.updateSpiffs(client, url); // client.setInsecure();
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());
if (callback_error) callback_error(-1);
return;
} }
switch (ret) { switch (ret) {
case HTTP_UPDATE_FAILED: case HTTP_UPDATE_FAILED:
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
// Don't restart ESP on HTTP errors, just return
if (callback_error) callback_error(httpUpdate.getLastError());
break; break;
case HTTP_UPDATE_NO_UPDATES: case HTTP_UPDATE_NO_UPDATES:
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_NO_UPDATES"); Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_NO_UPDATES");
if (callback_error) callback_error(-2);
break; break;
case HTTP_UPDATE_OK: case HTTP_UPDATE_OK:

View File

@@ -34,8 +34,8 @@ extends = env:esp32_base
lib_deps = lib_deps =
${env:esp32_base.lib_deps} ${env:esp32_base.lib_deps}
INA233 INA233
; upload_protocol = espota upload_protocol = espota
; upload_port = 192.168.18.18 upload_port = 192.168.5.205
[env:ESP32_INA226] [env:ESP32_INA226]
extends = env:esp32_base extends = env:esp32_base
@@ -43,7 +43,7 @@ lib_deps =
${env:esp32_base.lib_deps} ${env:esp32_base.lib_deps}
robtillaart/INA226@ ~0.6.4 robtillaart/INA226@ ~0.6.4
upload_protocol = espota upload_protocol = espota
upload_port = 192.168.18.18 upload_port = 192.168.6.46
build_flags = ${env:esp32_base.build_flags} -DUSE_INA226 build_flags = ${env:esp32_base.build_flags} -DUSE_INA226
[env:native] [env:native]

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, 5, 0} #define current_software_version Version{2, 4, 0}
#define REQUIRED_SPIFFS_VERSION Version{10, 0, 0} #define REQUIRED_SPIFFS_VERSION Version{10, 0, 0}
#define RESISTOR_VALUE 4 #define RESISTOR_VALUE 4

View File

@@ -70,7 +70,7 @@ void setup_api_endpoints(){
.ota_status = ota_status .ota_status = ota_status
}; };
xTaskCreate(run_ota_update_task, "RunOTAUpdate", 1024 * 8, (void *)&args, 1, NULL); xTaskCreate(run_ota_update_task, "RunOTAUpdate", 1024 * 12, (void *)&args, 1, NULL);
request->send(LittleFS, "/update_progress.html", "text/html", false, processor); request->send(LittleFS, "/update_progress.html", "text/html", false, processor);
}); });
} }

View File

@@ -33,8 +33,6 @@ void init_sensor(){
ina_sensor.setBusVoltageConversionTime(7); ina_sensor.setBusVoltageConversionTime(7);
ina_sensor.setShuntVoltageConversionTime(7); ina_sensor.setShuntVoltageConversionTime(7);
ina_sensor.setAverage(4); ina_sensor.setAverage(4);
// 111 - Shunt + Bus continous
ina_sensor.setMode(7);
#else #else
ina_sensor.begin(33, 32); ina_sensor.begin(33, 32);
ina_sensor.reset(); ina_sensor.reset();
@@ -54,6 +52,7 @@ void read_sensor_task(void* parameter)
String chip_id = ina_sensor.get_device_model(); String chip_id = ina_sensor.get_device_model();
LOG(ELOG_LEVEL_DEBUG, "Chip Model: %s", chip_id.c_str()); LOG(ELOG_LEVEL_DEBUG, "Chip Model: %s", chip_id.c_str());
#endif #endif
float bus_voltage = ina_sensor.getBusVoltage(); float bus_voltage = ina_sensor.getBusVoltage();
float shunt_voltage = ina_sensor.getShuntVoltage_mV() - zero_value; float shunt_voltage = ina_sensor.getShuntVoltage_mV() - zero_value;

View File

@@ -49,11 +49,9 @@ void update_started() {
} }
void update_finished() { void update_finished() {
LOG(ELOG_LEVEL_DEBUG, "OTA Update finished, rebooting after 2 seconds"); LOG(ELOG_LEVEL_DEBUG, "OTA Update finished");
ota_status.update_progress = -1; ota_status.update_progress = -1;
webSocket.textAll(String(-1).c_str()); webSocket.textAll(String(-1).c_str());
delay(2000);
ESP.restart();
} }
void update_progress(int cur, int total) { void update_progress(int cur, int total) {
@@ -68,7 +66,7 @@ void update_progress(int cur, int total) {
void update_error(int err) { void update_error(int err) {
LOG(ELOG_LEVEL_ERROR, "OTA Update error: %d", err); LOG(ELOG_LEVEL_ERROR, "OTA Update error: %d", err);
ota_status.update_progress = -2; ota_status.update_progress = -1;
} }
void check_update_task(void* parameter) { void check_update_task(void* parameter) {
@@ -104,6 +102,7 @@ void check_and_update_littleFS(OTA littlefs) {
if (isVersionNewer(current_spiffs_version, REQUIRED_SPIFFS_VERSION) && isVersionNewer(current_spiffs_version, latest_fs_version.version)) { if (isVersionNewer(current_spiffs_version, REQUIRED_SPIFFS_VERSION) && isVersionNewer(current_spiffs_version, latest_fs_version.version)) {
LOG(ELOG_LEVEL_DEBUG, "New SPIFFS version, running update now"); LOG(ELOG_LEVEL_DEBUG, "New SPIFFS version, running update now");
run_ota_spiffs_update(latest_fs_version.url, update_started, update_finished, update_progress, update_error); run_ota_spiffs_update(latest_fs_version.url, update_started, update_finished, update_progress, update_error);
ESP.restart();
// If we do not need a new version but one is available on the server // If we do not need a new version but one is available on the server
} else if (isVersionNewer(REQUIRED_SPIFFS_VERSION, latest_fs_version.version)) { } else if (isVersionNewer(REQUIRED_SPIFFS_VERSION, latest_fs_version.version)) {
@@ -156,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);
} }