From 39055ad0d25461a108323c35cbb3ee3456d57f43 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 31 Dec 2025 15:23:38 +0100 Subject: [PATCH 1/2] show firmware size in KB --- src/ESP32React/UploadFileService.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ESP32React/UploadFileService.cpp b/src/ESP32React/UploadFileService.cpp index c86a6e31c..8ef5bfc13 100644 --- a/src/ESP32React/UploadFileService.cpp +++ b/src/ESP32React/UploadFileService.cpp @@ -82,7 +82,7 @@ void UploadFileService::handleUpload(AsyncWebServerRequest * request, const Stri } #endif // it's firmware - initialize the ArduinoOTA updater - emsesp::EMSESP::logger().info("Uploading firmware file %s (size: %d bytes)", filename.c_str(), filesize); + emsesp::EMSESP::logger().info("Uploading firmware file %s (size: %d KB). Please wait...", filename.c_str(), filesize / 1024); // turn off UART to prevent interference with the upload emsesp::EMSuart::stop(); From 3fdc3704669d0288e98d692babeb5bf233b9f3c8 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 31 Dec 2025 15:25:05 +0100 Subject: [PATCH 2/2] clean up check_upgrade, remove OTA onProgress setting status each time --- src/core/emsesp.cpp | 14 ++++---- src/core/system.cpp | 79 ++++++++++++++++++++++----------------------- src/core/system.h | 2 +- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/core/emsesp.cpp b/src/core/emsesp.cpp index adf1c776e..04b5b1e34 100644 --- a/src/core/emsesp.cpp +++ b/src/core/emsesp.cpp @@ -1747,11 +1747,13 @@ void EMSESP::start() { webSettingsService.begin(); // load EMS-ESP Application settings - // do any system upgrades - if (system_.check_upgrade(factory_settings)) { - LOG_WARNING("System needs a restart to apply new settings. Please wait."); - system_.system_restart(); - }; + // perform any system upgrades + if (!factory_settings) { + if (system_.check_upgrade()) { + LOG_WARNING("System needs a restart to apply new settings. Please wait."); + system_.system_restart(); + }; + } // Load our library of known devices into stack mem. Names are stored in Flash memory device_library_ = { @@ -1831,7 +1833,7 @@ void EMSESP::loop() { // run the loop, unless we're in the middle of an OTA upload if (EMSESP::system_.systemStatus() == SYSTEM_STATUS::SYSTEM_STATUS_NORMAL || EMSESP::system_.systemStatus() == SYSTEM_STATUS::SYSTEM_STATUS_INVALID_GPIO) { - // check for GPIO Errors + // check for GPIO Errors - this is called once when booting if (EMSESP::system_.systemStatus() == SYSTEM_STATUS::SYSTEM_STATUS_INVALID_GPIO) { static bool only_once = false; if (!only_once) { diff --git a/src/core/system.cpp b/src/core/system.cpp index b2ab4de79..83b026cbb 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1412,58 +1412,49 @@ bool System::check_restore() { // handle upgrades from previous versions // this function will not be called on a clean install, with no settings files yet created // returns true if we need a reboot -bool System::check_upgrade(bool factory_settings) { +bool System::check_upgrade() { bool missing_version = true; std::string settingsVersion; - if (!factory_settings) { - // fetch current version from settings file - EMSESP::webSettingsService.read([&](WebSettings const & settings) { settingsVersion = settings.version.c_str(); }); + // fetch current version from settings file + EMSESP::webSettingsService.read([&](WebSettings const & settings) { settingsVersion = settings.version.c_str(); }); - // see if we're missing a version, will be < 3.5.0b13 from Dec 23 2022 - missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5)); - if (missing_version) { - LOG_WARNING("No version information found"); - settingsVersion = "3.5.0"; // this was the last stable version without version info - } - } else { - settingsVersion = EMSESP_APP_VERSION; // use the current version + // see if we're missing a version, will be < 3.5.0b13 from Dec 23 2022 + missing_version = (settingsVersion.empty() || (settingsVersion.length() < 5)); + if (missing_version) { + LOG_WARNING("No version information found"); + settingsVersion = "3.5.0"; // this was the last stable version without version info } version::Semver200_version settings_version(settingsVersion); - - if (!missing_version) { - LOG_DEBUG("Checking for version upgrades (settings file is v%d.%d.%d-%s)", - settings_version.major(), - settings_version.minor(), - settings_version.patch(), - settings_version.prerelease().c_str()); - } - - if (factory_settings) { - return true; // fresh install, do nothing, no reboot required - } - version::Semver200_version this_version(EMSESP_APP_VERSION); - bool save_version = true; - bool reboot_required = false; + std::string settings_version_type = settings_version.prerelease().empty() ? "" : ("-" + settings_version.prerelease()); + std::string this_version_type = this_version.prerelease().empty() ? "" : ("-" + this_version.prerelease()); + bool save_version = true; + bool reboot_required = false; + + LOG_DEBUG("Checking for version upgrades (settings file is v%d.%d.%d%s)", + settings_version.major(), + settings_version.minor(), + settings_version.patch(), + settings_version_type.c_str()); // compare versions if (this_version > settings_version) { // we need to do an upgrade if (missing_version) { - LOG_NOTICE("Upgrading to version %d.%d.%d-%s", this_version.major(), this_version.minor(), this_version.patch(), this_version.prerelease().c_str()); + LOG_NOTICE("Upgrading to version %d.%d.%d%s", this_version.major(), this_version.minor(), this_version.patch(), this_version_type); } else { - LOG_NOTICE("Upgrading from version %d.%d.%d-%s to %d.%d.%d-%s", + LOG_NOTICE("Upgrading from version %d.%d.%d%s to %d.%d.%d%s", settings_version.major(), settings_version.minor(), settings_version.patch(), - settings_version.prerelease().c_str(), + settings_version_type.c_str(), this_version.major(), this_version.minor(), this_version.patch(), - this_version.prerelease().c_str()); + this_version_type.c_str()); } // if we're coming from 3.4.4 or 3.5.0b14 which had no version stored then we need to apply new settings @@ -1518,11 +1509,9 @@ bool System::check_upgrade(bool factory_settings) { } return StateUpdateResult::UNCHANGED; }); - - } else if (this_version < settings_version) { // downgrading - LOG_NOTICE("Downgrading to version %d.%d.%d-%s", this_version.major(), this_version.minor(), this_version.patch(), this_version.prerelease().c_str()); + LOG_NOTICE("Downgrading to version %d.%d.%d%s", this_version.major(), this_version.minor(), this_version.patch(), this_version_type.c_str()); } else { save_version = false; // same version, do nothing } @@ -2686,23 +2675,29 @@ bool System::uploadFirmwareURL(const char * url) { return false; // error } - // check we have enough space for the upload in the ota partition int firmware_size = http.getSize(); - LOG_INFO("Firmware uploading (size: %d bytes). Please wait...", firmware_size); + + // check we have a valid size + if (firmware_size < 2097152) { // 2MB or greater is required + LOG_ERROR("Firmware upload failed - invalid size"); + http.end(); + return false; // error + } + + // check we have enough space for the upload in the ota partition if (!Update.begin(firmware_size)) { LOG_ERROR("Firmware upload failed - no space"); http.end(); return false; // error } + LOG_INFO("Firmware uploading (size: %d KB). Please wait...", firmware_size / 1024); + Shell::loop_all(); // flush log buffers so latest messages are shown in console // we're about to start the upload, set the status so the Web System Monitor spots it EMSESP::system_.systemStatus(SYSTEM_STATUS::SYSTEM_STATUS_UPLOADING); - // set a callback so we can monitor progress in the WebUI - Update.onProgress([](size_t progress, size_t total) { EMSESP::system_.systemStatus(SYSTEM_STATUS::SYSTEM_STATUS_UPLOADING + (progress * 100 / total)); }); - // get tcp stream and send it to Updater WiFiClient * stream = http.getStreamPtr(); if (Update.writeStream(*stream) != firmware_size) { @@ -2792,8 +2787,10 @@ bool System::command_read(const char * value, const int8_t id) { // set the system status code - SYSTEM_STATUS in system.h void System::systemStatus(uint8_t status_code) { - systemStatus_ = status_code; - LOG_DEBUG("Setting System status code %d", status_code); + if (systemStatus_ != status_code) { + systemStatus_ = status_code; + LOG_DEBUG("Setting System status code %d", status_code); + } } uint8_t System::systemStatus() { diff --git a/src/core/system.h b/src/core/system.h index 91ee58722..3d2c9c6c4 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -122,7 +122,7 @@ class System { void show_mem(const char * note); void store_settings(class WebSettings & settings); void syslog_init(); - bool check_upgrade(bool factory_settings); + bool check_upgrade(); bool check_restore(); void heartbeat_json(JsonObject output);