Added SPIFFS updating
All checks were successful
Test compiling project / test (push) Successful in 2m38s
All checks were successful
Test compiling project / test (push) Successful in 2m38s
This commit is contained in:
53
src/main.cpp
53
src/main.cpp
@@ -24,6 +24,7 @@
|
||||
#include "networking/json_builder.h"
|
||||
#include "networking/responses.h"
|
||||
#include <fetchOTA.h>
|
||||
#include <ESP32Ping.h>
|
||||
|
||||
Preferences prefs;
|
||||
|
||||
@@ -35,23 +36,11 @@ extern SensorData shunt_data;
|
||||
|
||||
extern "C" int rom_phy_get_vdd33();
|
||||
|
||||
Version current_spiffs_version;
|
||||
|
||||
AsyncWebServer server(80);
|
||||
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||
|
||||
|
||||
|
||||
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);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
prefs.begin("waterlevel", false);
|
||||
@@ -75,6 +64,19 @@ void setup()
|
||||
|
||||
Log.verbose("Beginning SPIFFS");
|
||||
SPIFFS.begin(true);
|
||||
|
||||
// Read the current SPIFFS version from the versions file on the spiffs
|
||||
File file = SPIFFS.open("/version", FILE_READ);
|
||||
if (!file) {
|
||||
Serial.println("Failed to open version file for reading");
|
||||
} else {
|
||||
String version = file.readStringUntil('\n');
|
||||
Log.verbose("Version: %s", version);
|
||||
current_spiffs_version = parseVersion(version.c_str());
|
||||
Log.verbose("Current SPIFFS Version: %d.%d.%d", current_spiffs_version.major, current_spiffs_version.minor, current_spiffs_version.patch);
|
||||
}
|
||||
|
||||
|
||||
Log.verbose("SPIFFS initialized");
|
||||
display_error_code(19);
|
||||
|
||||
@@ -162,13 +164,6 @@ void setup()
|
||||
}
|
||||
request->send(SPIFFS, "/settings.html", "text/html", false); // TODO add proper return templating
|
||||
});
|
||||
|
||||
server.on("/ota", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
Serial.println("OTA Task start");
|
||||
xTaskCreate(run_ota, "OTATask", 1024 * 8, NULL, 1, NULL);
|
||||
|
||||
request->send(200, "text/plain", "OTA done");
|
||||
});
|
||||
|
||||
setup_api_endpoints();
|
||||
|
||||
@@ -220,6 +215,22 @@ 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);
|
||||
|
||||
// Wait until there is network connection
|
||||
while (true) {
|
||||
if (WiFi.status() == WL_CONNECTED || ETH.localIP()) {
|
||||
int pingResult = Ping.ping("8.8.8.8"); // Use Google's public DNS server as a test IP
|
||||
if (pingResult >= 0) {
|
||||
Log.verbose("Network connection established");
|
||||
break;
|
||||
} else {
|
||||
Log.verbose("Network not ready, retrying...");
|
||||
}
|
||||
} else {
|
||||
Log.verbose("No WiFi or Ethernet connection, retrying...");
|
||||
}
|
||||
delay(200); // Delay to prevent rapid retry
|
||||
}
|
||||
xTaskCreate(check_update_task, "CheckUpdateTask", 1024 * 8, NULL, 1, NULL);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user