mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
rename upload status
This commit is contained in:
@@ -575,20 +575,20 @@ void System::led_init(bool refresh) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns true if OTA is uploading
|
// returns true if OTA is uploading
|
||||||
bool System::upload_status() {
|
bool System::upload_isrunning() {
|
||||||
#if defined(EMSESP_STANDALONE)
|
#if defined(EMSESP_STANDALONE)
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
return upload_status_ || Update.isRunning();
|
return upload_isrunning_ || Update.isRunning();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::upload_status(bool in_progress) {
|
void System::upload_isrunning(bool in_progress) {
|
||||||
// if we've just started an upload
|
// if we've just started an upload
|
||||||
if (!upload_status_ && in_progress) {
|
if (!upload_isrunning_ && in_progress) {
|
||||||
EMSuart::stop();
|
EMSuart::stop();
|
||||||
}
|
}
|
||||||
upload_status_ = in_progress;
|
upload_isrunning_ = in_progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks system health and handles LED flashing wizardry
|
// checks system health and handles LED flashing wizardry
|
||||||
@@ -1863,29 +1863,30 @@ bool System::uploadFirmwareURL(const char * url) {
|
|||||||
|
|
||||||
static String saved_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) {
|
if (url && strlen(url) > 0) {
|
||||||
saved_url = url;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure we have a valid URL
|
// make sure we have a valid URL
|
||||||
if (saved_url.isEmpty()) {
|
if (saved_url.isEmpty()) {
|
||||||
return false;
|
return false; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure temporary client
|
// Configure temporary client
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS); // important for GitHub 302's
|
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); // important for GitHub 302's
|
||||||
http.useHTTP10(true);
|
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);
|
http.begin(saved_url);
|
||||||
|
|
||||||
// start a connection
|
// start a connection, returns -1 if fails
|
||||||
int httpCode = http.GET();
|
int httpCode = http.GET();
|
||||||
if (httpCode != HTTP_CODE_OK) {
|
if (httpCode != HTTP_CODE_OK) {
|
||||||
LOG_ERROR("Firmware upload failed - HTTP code %u", httpCode);
|
LOG_ERROR("Firmware upload failed - HTTP code %d", httpCode);
|
||||||
return false;
|
return false; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
// check we have enough space for the upload in the ota partition
|
// 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);
|
LOG_INFO("Firmware uploading (file: %s, size: %d bytes). Please wait...", saved_url.c_str(), firmware_size);
|
||||||
if (!Update.begin(firmware_size)) {
|
if (!Update.begin(firmware_size)) {
|
||||||
LOG_ERROR("Firmware upload failed - no space");
|
LOG_ERROR("Firmware upload failed - no space");
|
||||||
return false;
|
return false; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
// flush log buffers so latest messages are shown
|
// flush log buffers so latest messages are shown
|
||||||
@@ -1903,17 +1904,17 @@ bool System::uploadFirmwareURL(const char * url) {
|
|||||||
WiFiClient * stream = http.getStreamPtr();
|
WiFiClient * stream = http.getStreamPtr();
|
||||||
if (Update.writeStream(*stream) != firmware_size) {
|
if (Update.writeStream(*stream) != firmware_size) {
|
||||||
LOG_ERROR("Firmware upload failed - size differences");
|
LOG_ERROR("Firmware upload failed - size differences");
|
||||||
return false;
|
return false; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Update.end(true)) {
|
if (!Update.end(true)) {
|
||||||
LOG_ERROR("Firmware upload failed - general error");
|
LOG_ERROR("Firmware upload failed - general error");
|
||||||
return false;
|
return false; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
http.end();
|
http.end();
|
||||||
|
|
||||||
EMSESP::system_.upload_status(false);
|
EMSESP::system_.upload_isrunning(false);
|
||||||
saved_url.clear(); // prevent from downloading again
|
saved_url.clear(); // prevent from downloading again
|
||||||
|
|
||||||
LOG_INFO("Firmware uploaded successfully. Restarting...");
|
LOG_INFO("Firmware uploaded successfully. Restarting...");
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ class System {
|
|||||||
|
|
||||||
void store_nvs_values();
|
void store_nvs_values();
|
||||||
void system_restart(const char * partition = nullptr);
|
void system_restart(const char * partition = nullptr);
|
||||||
void upload_status(bool in_progress);
|
void upload_isrunning(bool in_progress);
|
||||||
bool upload_status();
|
bool upload_isrunning();
|
||||||
void show_mem(const char * note);
|
void show_mem(const char * note);
|
||||||
void reload_settings();
|
void reload_settings();
|
||||||
void syslog_init();
|
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
|
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;
|
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 ethernet_connected_ = false;
|
||||||
bool has_ipv6_ = false;
|
bool has_ipv6_ = false;
|
||||||
|
|
||||||
|
|||||||
@@ -529,7 +529,7 @@ void WebSchedulerService::loop() {
|
|||||||
void WebSchedulerService::scheduler_task(void * pvParameters) {
|
void WebSchedulerService::scheduler_task(void * pvParameters) {
|
||||||
while (1) {
|
while (1) {
|
||||||
delay(10); // no need to hurry
|
delay(10); // no need to hurry
|
||||||
if (!EMSESP::system_.upload_status()) {
|
if (!EMSESP::system_.upload_isrunning()) {
|
||||||
EMSESP::webSchedulerService.loop();
|
EMSESP::webSchedulerService.loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ void WebStatusService::hardwareStatus(AsyncWebServerRequest * request) {
|
|||||||
root["status"] = "restarting";
|
root["status"] = "restarting";
|
||||||
EMSESP::system_.restart_requested(true); // tell emsesp loop to start restart
|
EMSESP::system_.restart_requested(true); // tell emsesp loop to start restart
|
||||||
} else {
|
} else {
|
||||||
root["status"] = EMSESP::system_.upload_status() ? "uploading" : "ready";
|
root["status"] = EMSESP::system_.upload_isrunning() ? "uploading" : "ready";
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user