This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <Preferences.h>
|
||||
#include <fetchOTA.h>
|
||||
#include <AsyncWebSocket.h>
|
||||
#include "log.h"
|
||||
|
||||
extern Preferences prefs;
|
||||
extern OTAStatus ota_status;
|
||||
@@ -35,12 +36,12 @@ String processor(const String& var)
|
||||
|
||||
// OTA Callbacks
|
||||
void update_started() {
|
||||
logger.log(0, DEBUG, "OTA Update started");
|
||||
LOG(DEBUG, "OTA Update started");
|
||||
ota_status.update_progress = 0;
|
||||
}
|
||||
|
||||
void update_finished() {
|
||||
logger.log(0, DEBUG, "OTA Update finished");
|
||||
LOG(DEBUG, "OTA Update finished");
|
||||
ota_status.update_progress = -1;
|
||||
webSocket.textAll(String(-1).c_str());
|
||||
}
|
||||
@@ -49,14 +50,14 @@ void update_progress(int cur, int total) {
|
||||
ota_status.update_progress = 0;
|
||||
if (cur != 0 ) {
|
||||
ota_status.update_progress = int(float(cur)/float(total)*100);
|
||||
logger.log(0, DEBUG, "OTA Update progress: %d/%d, %i", cur, total, ota_status.update_progress);
|
||||
LOG(DEBUG, "OTA Update progress: %d/%d, %i", cur, total, ota_status.update_progress);
|
||||
}
|
||||
webSocket.textAll(String(ota_status.update_progress).c_str());
|
||||
logger.log(0, DEBUG, "OTA Update progress: %d/%d", cur, total);
|
||||
LOG(DEBUG, "OTA Update progress: %d/%d", cur, total);
|
||||
}
|
||||
|
||||
void update_error(int err) {
|
||||
logger.log(0, ERROR, "OTA Update error: %d", err);
|
||||
LOG(ERROR, "OTA Update error: %d", err);
|
||||
ota_status.update_progress = -2;
|
||||
}
|
||||
|
||||
@@ -75,20 +76,20 @@ void check_update_task(void* parameter) {
|
||||
// If there is a SPIFSS update it will be ran automatically, as SPIFFS is necessary for the firmware to run
|
||||
Firmware latest_spiff_version = spiffs_fs.getLatestVersionOnServer();
|
||||
|
||||
logger.log(0, DEBUG, "Required SPIFFS Version: %d.%d.%d; Current SPIFFS version: %d.%d.%d; Server SPIFFS Version: %d.%d.%d", REQUIRED_SPIFFS_VERSION.major, REQUIRED_SPIFFS_VERSION.minor, REQUIRED_SPIFFS_VERSION.patch, current_spiffs_version.major, current_spiffs_version.minor, current_spiffs_version.patch, latest_spiff_version.version.major, latest_spiff_version.version.minor, latest_spiff_version.version.patch);
|
||||
LOG(DEBUG, "Required SPIFFS Version: %d.%d.%d; Current SPIFFS version: %d.%d.%d; Server SPIFFS Version: %d.%d.%d", REQUIRED_SPIFFS_VERSION.major, REQUIRED_SPIFFS_VERSION.minor, REQUIRED_SPIFFS_VERSION.patch, current_spiffs_version.major, current_spiffs_version.minor, current_spiffs_version.patch, latest_spiff_version.version.major, latest_spiff_version.version.minor, latest_spiff_version.version.patch);
|
||||
|
||||
if (latest_spiff_version.valid) {
|
||||
if (isVersionNewer(current_spiffs_version, REQUIRED_SPIFFS_VERSION)) {
|
||||
// If Required SPIFFS version is newer than current version, update
|
||||
logger.log(0, DEBUG, "New SPIFFS version, running update now");
|
||||
LOG(DEBUG, "New SPIFFS version, running update now");
|
||||
run_ota_spiffs_update(latest_spiff_version.url, update_started, update_finished, update_progress, update_error);
|
||||
// Reboot just to be safe
|
||||
ESP.restart();
|
||||
} else if (isVersionNewer(REQUIRED_SPIFFS_VERSION, latest_spiff_version.version)) {
|
||||
// If Server has new SPIFFS version but it's not required
|
||||
logger.log(0, DEBUG, "New SPIFFS version available: %d.%d.%d, current version: %d.%d.%d but not necessary to update", latest_spiff_version.version.major, latest_spiff_version.version.minor, latest_spiff_version.version.patch, REQUIRED_SPIFFS_VERSION.major, REQUIRED_SPIFFS_VERSION.minor, REQUIRED_SPIFFS_VERSION.patch);
|
||||
LOG(DEBUG, "New SPIFFS version available: %d.%d.%d, current version: %d.%d.%d but not necessary to update", latest_spiff_version.version.major, latest_spiff_version.version.minor, latest_spiff_version.version.patch, REQUIRED_SPIFFS_VERSION.major, REQUIRED_SPIFFS_VERSION.minor, REQUIRED_SPIFFS_VERSION.patch);
|
||||
} else {
|
||||
logger.log(0, DEBUG, "No new SPIFFS version available");
|
||||
LOG(DEBUG, "No new SPIFFS version available");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,11 +97,11 @@ void check_update_task(void* parameter) {
|
||||
while (true) {
|
||||
Firmware fw = ota.getLatestVersionOnServer();
|
||||
if (fw.valid) {
|
||||
logger.log(0, DEBUG, "New firmware available: %d.%d.%d, current version: %d.%d.%d", fw.version.major, fw.version.minor, fw.version.patch, current_software_version.major, current_software_version.minor, current_software_version.patch);
|
||||
LOG(DEBUG, "New firmware available: %d.%d.%d, current version: %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.latest_version = fw.version;
|
||||
ota_status.update_url = fw.url;
|
||||
if (isVersionNewer(current_software_version, fw.version)) {
|
||||
logger.log(0, DEBUG, "Remote version is newer than current version");
|
||||
LOG(DEBUG, "Remote version is newer than current version");
|
||||
ota_status.update_available = true;
|
||||
} else {
|
||||
ota_status.update_available = false;
|
||||
@@ -111,7 +112,7 @@ void check_update_task(void* parameter) {
|
||||
ota_status.update_available = false;
|
||||
}
|
||||
|
||||
logger.log(0, DEBUG, "No new firmware available");
|
||||
LOG(DEBUG, "No new firmware available");
|
||||
}
|
||||
delay(1000 * 60 * 1);
|
||||
}
|
||||
@@ -121,7 +122,7 @@ void check_update_task(void* parameter) {
|
||||
|
||||
void run_ota_update_task(void* parameter) {
|
||||
TaskArgs_t *args = (TaskArgs_t *) parameter;
|
||||
logger.log(0, DEBUG, "Running OTA upgrade now with URL: %s", args->ota_status.update_url.c_str());
|
||||
LOG(DEBUG, "Running OTA upgrade now with URL: %s", args->ota_status.update_url.c_str());
|
||||
run_ota_update(args->ota_status.update_url, update_started, update_finished, update_progress, update_error);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user