From 722e7f38fc7cfc405b6a2068785694e9601758b4 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 1 Sep 2024 13:44:48 +0200 Subject: [PATCH] rename upload status --- src/system.cpp | 35 +++++++++++++++++---------------- src/system.h | 6 +++--- src/web/WebSchedulerService.cpp | 2 +- src/web/WebStatusService.cpp | 2 +- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/system.cpp b/src/system.cpp index 2a06d74dc..cec6e809c 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -575,20 +575,20 @@ void System::led_init(bool refresh) { } // returns true if OTA is uploading -bool System::upload_status() { +bool System::upload_isrunning() { #if defined(EMSESP_STANDALONE) return false; #else - return upload_status_ || Update.isRunning(); + return upload_isrunning_ || Update.isRunning(); #endif } -void System::upload_status(bool in_progress) { +void System::upload_isrunning(bool in_progress) { // if we've just started an upload - if (!upload_status_ && in_progress) { + if (!upload_isrunning_ && in_progress) { EMSuart::stop(); } - upload_status_ = in_progress; + upload_isrunning_ = in_progress; } // checks system health and handles LED flashing wizardry @@ -1863,29 +1863,30 @@ bool System::uploadFirmwareURL(const char * url) { static String saved_url; - // if the URL is not empty, save it for later + // if the URL is not empty, store the URL for the 2nd pass if (url && strlen(url) > 0) { saved_url = url; - EMSESP::system_.upload_status(true); // tell EMS-ESP we're ready to start the uploading process + EMSESP::system_.upload_isrunning(true); // tell EMS-ESP we're ready to start the uploading process return true; } // make sure we have a valid URL if (saved_url.isEmpty()) { - return false; + return false; // error } // Configure temporary client HTTPClient http; - http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS); // important for GitHub 302's - http.useHTTP10(true); + http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); // important for GitHub 302's + http.setTimeout(8000); + http.useHTTP10(true); // use HTTP/1.0 for update since the update handler not support any transfer Encoding http.begin(saved_url); - // start a connection + // start a connection, returns -1 if fails int httpCode = http.GET(); if (httpCode != HTTP_CODE_OK) { - LOG_ERROR("Firmware upload failed - HTTP code %u", httpCode); - return false; + LOG_ERROR("Firmware upload failed - HTTP code %d", httpCode); + return false; // error } // check we have enough space for the upload in the ota partition @@ -1893,7 +1894,7 @@ bool System::uploadFirmwareURL(const char * url) { LOG_INFO("Firmware uploading (file: %s, size: %d bytes). Please wait...", saved_url.c_str(), firmware_size); if (!Update.begin(firmware_size)) { LOG_ERROR("Firmware upload failed - no space"); - return false; + return false; // error } // flush log buffers so latest messages are shown @@ -1903,17 +1904,17 @@ bool System::uploadFirmwareURL(const char * url) { WiFiClient * stream = http.getStreamPtr(); if (Update.writeStream(*stream) != firmware_size) { LOG_ERROR("Firmware upload failed - size differences"); - return false; + return false; // error } if (!Update.end(true)) { LOG_ERROR("Firmware upload failed - general error"); - return false; + return false; // error } http.end(); - EMSESP::system_.upload_status(false); + EMSESP::system_.upload_isrunning(false); saved_url.clear(); // prevent from downloading again LOG_INFO("Firmware uploaded successfully. Restarting..."); diff --git a/src/system.h b/src/system.h index 3852df045..5ec31d5c9 100644 --- a/src/system.h +++ b/src/system.h @@ -76,8 +76,8 @@ class System { void store_nvs_values(); void system_restart(const char * partition = nullptr); - void upload_status(bool in_progress); - bool upload_status(); + void upload_isrunning(bool in_progress); + bool upload_isrunning(); void show_mem(const char * note); void reload_settings(); void syslog_init(); @@ -340,7 +340,7 @@ class System { uint8_t healthcheck_ = HEALTHCHECK_NO_NETWORK | HEALTHCHECK_NO_BUS; // start with all flags set, no wifi and no ems bus connection uint32_t last_system_check_ = 0; - bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload + bool upload_isrunning_ = false; // true if we're in the middle of a OTA firmware upload bool ethernet_connected_ = false; bool has_ipv6_ = false; diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index 43116d0cc..040c0c2b0 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -529,7 +529,7 @@ void WebSchedulerService::loop() { void WebSchedulerService::scheduler_task(void * pvParameters) { while (1) { delay(10); // no need to hurry - if (!EMSESP::system_.upload_status()) { + if (!EMSESP::system_.upload_isrunning()) { EMSESP::webSchedulerService.loop(); } } diff --git a/src/web/WebStatusService.cpp b/src/web/WebStatusService.cpp index 465e3a5fd..4dab1d55c 100644 --- a/src/web/WebStatusService.cpp +++ b/src/web/WebStatusService.cpp @@ -144,7 +144,7 @@ void WebStatusService::hardwareStatus(AsyncWebServerRequest * request) { root["status"] = "restarting"; EMSESP::system_.restart_requested(true); // tell emsesp loop to start restart } else { - root["status"] = EMSESP::system_.upload_status() ? "uploading" : "ready"; + root["status"] = EMSESP::system_.upload_isrunning() ? "uploading" : "ready"; } #endif