Added SPIFFS updating
All checks were successful
Test compiling project / test (push) Successful in 2m38s

This commit is contained in:
2025-02-19 20:48:26 +01:00
parent 0cd42484f9
commit ab16379e73
7 changed files with 105 additions and 23 deletions

View File

@@ -13,6 +13,7 @@ OTA::OTA(String server_url, Version currentVersion, String currentDeviceConfigur
_serverUrl = server_url;
_currentVersion = currentVersion;
_current_device_configuration = currentDeviceConfiguration;
_current_device_configuration.toLowerCase();
}
@@ -42,6 +43,7 @@ Firmware OTA::getLatestVersionOnServer() {
for (JsonObject config : doc["Configurations"].as<JsonArray>()) {
if (config.containsKey("Version") && config.containsKey("URL") && config.containsKey("Config")) {
String deviceConfig = config["Config"].as<String>();
deviceConfig.toLowerCase();
if (deviceConfig == _current_device_configuration) {
configs.push_back(Configuration{
parseVersion(config["Version"]),
@@ -107,7 +109,6 @@ void run_ota_update(String url, std::function<void()> callback_started, std::fu
Log.error("URL is not valid: \n%s", url.c_str());
}
switch (ret) {
case HTTP_UPDATE_FAILED:
Log.error("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
@@ -123,6 +124,45 @@ void run_ota_update(String url, std::function<void()> callback_started, std::fu
}
}
void run_ota_spiffs_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) {
Log.verbose("Starting OTA SPIFFS upgrade");
HTTPUpdate httpUpdate;
httpUpdate.onStart(callback_started);
httpUpdate.onEnd(callback_finished);
httpUpdate.onProgress(callback_progress);
httpUpdate.onError(callback_error);
Log.verbose("Defined callbacks, Starting update now");
t_httpUpdate_return ret;
if (url.startsWith("https")) {
Log.verbose("HTTPS URL");
WiFiClientSecure client;
client.setInsecure();
ret = httpUpdate.updateSpiffs(client, url);
} else if (url.startsWith("http")) {
Log.verbose("HTTP URL");
WiFiClient client;
ret = httpUpdate.updateSpiffs(client, url);
} else {
Log.error("URL is not valid: \n%s", url.c_str());
}
switch (ret) {
case HTTP_UPDATE_FAILED:
Log.error("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Log.error("HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
Log.verbose("SPIFFS Update done");
break;
}
}
#endif

View File

@@ -27,5 +27,6 @@ class OTA {
};
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_spiffs_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);
#endif