Cleanup + Bugfix
All checks were successful
Test project compilation / test (push) Successful in 3m43s
All checks were successful
Test project compilation / test (push) Successful in 3m43s
This commit is contained in:
@@ -1 +1 @@
|
|||||||
9
|
10
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#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>
|
||||||
@@ -97,11 +98,11 @@ 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;
|
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
|
||||||
|
|
||||||
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;
|
WiFiClientSecure client;
|
||||||
// client.setInsecure();
|
// client.setInsecure();
|
||||||
ret = httpUpdate.update(client, url);
|
ret = httpUpdate.update(client, url);
|
||||||
} else if (url.startsWith("http")) {
|
} 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);
|
ret = httpUpdate.update(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:
|
||||||
@@ -136,12 +142,12 @@ 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;
|
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
|
||||||
|
|
||||||
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;
|
WiFiClientSecure client;
|
||||||
// client.setInsecure();
|
client.setInsecure();
|
||||||
ret = httpUpdate.updateSpiffs(client, url);
|
ret = httpUpdate.updateSpiffs(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");
|
||||||
@@ -149,15 +155,20 @@ void run_ota_spiffs_update(String url, std::function<void()> callback_started,
|
|||||||
ret = httpUpdate.updateSpiffs(client, url);
|
ret = httpUpdate.updateSpiffs(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:
|
||||||
|
|||||||
@@ -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.5.205
|
; upload_port = 192.168.18.18
|
||||||
|
|
||||||
[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.6.45
|
upload_port = 192.168.18.18
|
||||||
build_flags = ${env:esp32_base.build_flags} -DUSE_INA226
|
build_flags = ${env:esp32_base.build_flags} -DUSE_INA226
|
||||||
|
|
||||||
[env:native]
|
[env:native]
|
||||||
|
|||||||
@@ -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, 5, 0}
|
||||||
#define REQUIRED_SPIFFS_VERSION Version{9, 0, 0}
|
#define REQUIRED_SPIFFS_VERSION Version{10, 0, 0}
|
||||||
|
|
||||||
#define RESISTOR_VALUE 4
|
#define RESISTOR_VALUE 4
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ 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();
|
||||||
@@ -52,7 +54,6 @@ 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;
|
||||||
|
|
||||||
|
|||||||
@@ -49,9 +49,11 @@ void update_started() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update_finished() {
|
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;
|
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) {
|
||||||
@@ -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)) {
|
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)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user