This commit is contained in:
@@ -7,6 +7,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_software_version Version{0, 0, 7}
|
||||
#define current_software_version Version{0, 0, 8}
|
||||
|
||||
#define RESISTOR_VALUE 4
|
||||
27
src/main.cpp
27
src/main.cpp
@@ -37,30 +37,16 @@ extern "C" int rom_phy_get_vdd33();
|
||||
|
||||
AsyncWebServer server(80);
|
||||
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||
void update_started() {
|
||||
Log.verbose("OTA Update started");
|
||||
}
|
||||
|
||||
void update_finished() {
|
||||
Log.verbose("OTA Update finished");
|
||||
}
|
||||
|
||||
void update_progress(int cur, int total) {
|
||||
Log.verbose("OTA Update progress: %d/%d", cur, total);
|
||||
}
|
||||
|
||||
void update_error(int err) {
|
||||
Log.error("OTA Update error: %d", err);
|
||||
}
|
||||
|
||||
|
||||
void run_ota(void* parameter) {
|
||||
OTA ota("https://iot.tobiasmaier.me/firmware/waterlevel", "1.1.1", "INA233");
|
||||
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());
|
||||
Log.verbose("Error message: %s", fw.error.c_str());
|
||||
ota.run_ota_update(fw.url, update_started, update_finished, update_progress, update_error);
|
||||
// OTA ota("https://iot.tobiasmaier.me/firmware/waterlevel", "1.1.1", "INA233");
|
||||
// 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());
|
||||
// Log.verbose("Error message: %s", fw.error.c_str());
|
||||
// ota.run_ota_update(fw.url, update_started, update_finished, update_progress, update_error);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
@@ -234,6 +220,7 @@ void setup()
|
||||
xTaskCreate(display_task, "DisplayTask", 10000, NULL, 1, NULL);
|
||||
xTaskCreate(read_sensor_task, "ReadSensorTask", 2048, NULL, 1, NULL);
|
||||
xTaskCreate(collect_internal_telemetry_task, "InternalTelemetryTask", 2048, NULL, 1, NULL);
|
||||
xTaskCreate(check_update_task, "CheckUpdateTask", 1024 * 8, NULL, 1, NULL);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
#include <ArduinoLog.h>
|
||||
#include "../global_data/defines.h"
|
||||
#include <Preferences.h>
|
||||
#include <fetchOTA.h>
|
||||
|
||||
extern Preferences prefs;
|
||||
extern OTAStatus ota_status;
|
||||
|
||||
void printSuffix(Print* _logOutput, int logLevel)
|
||||
{
|
||||
@@ -37,4 +39,44 @@ String processor(const String& var)
|
||||
}
|
||||
|
||||
return String("Test");
|
||||
}
|
||||
|
||||
// OTA Callbacks
|
||||
void update_started() {
|
||||
Log.verbose("OTA Update started");
|
||||
ota_status.update_progress = 0;
|
||||
}
|
||||
|
||||
void update_finished() {
|
||||
Log.verbose("OTA Update finished");
|
||||
ota_status.update_progress = -1;
|
||||
}
|
||||
|
||||
void update_progress(int cur, int total) {
|
||||
ota_status.update_progress = total/cur;
|
||||
Log.verbose("OTA Update progress: %d/%d", cur, total);
|
||||
}
|
||||
|
||||
void update_error(int err) {
|
||||
Log.error("OTA Update error: %d", err);
|
||||
ota_status.update_progress = -2;
|
||||
}
|
||||
|
||||
void check_update_task(void* parameter) {
|
||||
#ifdef USE_INA226
|
||||
OTA ota("https://iot.tobiasmaier.me/firmware/waterlevel", current_software_version, "INA226");
|
||||
#else
|
||||
OTA ota("https://iot.tobiasmaier.me/firmware/waterlevel", current_software_version, "INA233");
|
||||
#endif
|
||||
while (true) {
|
||||
Firmware fw = ota.getLatestVersionOnServer();
|
||||
if (fw.valid) {
|
||||
Log.verbose("New firmware available: %d.%d.%d, current versio: %d.%d.%d", fw.version.major, fw.version.minor, fw.version.patch, current_software_version.major, current_software_version.minor, current_software_version.patch);
|
||||
ota_status.update_available = true;
|
||||
ota_status.latest_version = fw.version;
|
||||
} else {
|
||||
Log.verbose("No new firmware available");
|
||||
}
|
||||
delay(1000 * 60 * 1);
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,5 @@
|
||||
void printSuffix(Print* _logOutput, int logLevel);
|
||||
void print_prefix(Print* _logOutput, int logLevel);
|
||||
bool is_error(ActiveErrors active_errors);
|
||||
String processor(const String& var);
|
||||
String processor(const String& var);
|
||||
void check_update_task(void* parameter);
|
||||
Reference in New Issue
Block a user