Cleanup + Bugfix
All checks were successful
Test project compilation / test (push) Successful in 3m43s

This commit is contained in:
2026-03-29 17:46:41 +02:00
parent aa69687ee8
commit cfc8438042
7 changed files with 28 additions and 15 deletions

View File

@@ -1 +1 @@
9
10

View File

@@ -6,6 +6,7 @@
#include <ArduinoJson.h>
#include <HTTPClient.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <vector>
#include <Elog.h>
#include <HTTPUpdate.h>
@@ -97,11 +98,11 @@ void run_ota_update(String url, std::function<void()> callback_started, std::fu
httpUpdate.onError(callback_error);
Logger.log(0, ELOG_LEVEL_DEBUG, "Defined callbacks, Starting update now");
t_httpUpdate_return ret;
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
if (url.startsWith("https")) {
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL");
WiFiClient client;
WiFiClientSecure client;
// client.setInsecure();
ret = httpUpdate.update(client, url);
} else if (url.startsWith("http")) {
@@ -110,15 +111,20 @@ void run_ota_update(String url, std::function<void()> callback_started, std::fu
ret = httpUpdate.update(client, url);
} else {
Logger.log(0, ELOG_LEVEL_ERROR, "URL is not valid: \n%s", url.c_str());
if (callback_error) callback_error(-1);
return;
}
switch (ret) {
case HTTP_UPDATE_FAILED:
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;
case HTTP_UPDATE_NO_UPDATES:
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_NO_UPDATES");
if (callback_error) callback_error(-2);
break;
case HTTP_UPDATE_OK:
@@ -136,12 +142,12 @@ void run_ota_spiffs_update(String url, std::function<void()> callback_started,
httpUpdate.onError(callback_error);
Logger.log(0, ELOG_LEVEL_DEBUG, "Defined callbacks, Starting update now");
t_httpUpdate_return ret;
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
if (url.startsWith("https")) {
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL");
WiFiClient client;
// client.setInsecure();
WiFiClientSecure client;
client.setInsecure();
ret = httpUpdate.updateSpiffs(client, url);
} else if (url.startsWith("http")) {
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTP URL");
@@ -149,15 +155,20 @@ void run_ota_spiffs_update(String url, std::function<void()> callback_started,
ret = httpUpdate.updateSpiffs(client, url);
} else {
Logger.log(0, ELOG_LEVEL_ERROR, "URL is not valid: \n%s", url.c_str());
if (callback_error) callback_error(-1);
return;
}
switch (ret) {
case HTTP_UPDATE_FAILED:
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;
case HTTP_UPDATE_NO_UPDATES:
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_NO_UPDATES");
if (callback_error) callback_error(-2);
break;
case HTTP_UPDATE_OK:

View File

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

View File

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

View File

@@ -51,7 +51,7 @@ void setup_api_endpoints(){
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;
serializeJson(build_ota_json(ota_status), output);
request->send(200, "application/json", output);

View File

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

View File

@@ -49,9 +49,11 @@ void update_started() {
}
void update_finished() {
LOG(ELOG_LEVEL_DEBUG, "OTA Update finished");
LOG(ELOG_LEVEL_DEBUG, "OTA Update finished, rebooting after 2 seconds");
ota_status.update_progress = -1;
webSocket.textAll(String(-1).c_str());
delay(2000);
ESP.restart();
}
void update_progress(int cur, int total) {
@@ -102,7 +104,6 @@ void check_and_update_littleFS(OTA littlefs) {
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");
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
} else if (isVersionNewer(REQUIRED_SPIFFS_VERSION, latest_fs_version.version)) {