mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 03:06:33 +00:00
Refactor web upload
This commit is contained in:
parent
86ee7a411c
commit
d53fa3234d
@ -380,23 +380,22 @@ void SleepDelay(uint32_t mseconds) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void) {
|
void Scheduler(void) {
|
||||||
uint32_t my_sleep = millis();
|
|
||||||
|
|
||||||
// check LEAmDNS.h
|
|
||||||
// MDNS.update() needs to be called in main loop
|
|
||||||
#ifdef ESP8266 //Not needed with esp32 mdns
|
|
||||||
#ifdef USE_DISCOVERY
|
|
||||||
#ifdef WEBSERVER_ADVERTISE
|
|
||||||
// previously this was only called in WifiCheckIp() and that causes delays in responses to mdns
|
|
||||||
MdnsUpdate();
|
|
||||||
#endif // WEBSERVER_ADVERTISE
|
|
||||||
#endif // USE_DISCOVERY
|
|
||||||
#endif // ESP8266
|
|
||||||
|
|
||||||
XdrvCall(FUNC_LOOP);
|
XdrvCall(FUNC_LOOP);
|
||||||
XsnsCall(FUNC_LOOP);
|
XsnsCall(FUNC_LOOP);
|
||||||
|
|
||||||
|
// check LEAmDNS.h
|
||||||
|
// MDNS.update() needs to be called in main loop
|
||||||
|
#ifdef ESP8266 // Not needed with esp32 mdns
|
||||||
|
#ifdef USE_DISCOVERY
|
||||||
|
#ifdef USE_WEBSERVER
|
||||||
|
#ifdef WEBSERVER_ADVERTISE
|
||||||
|
MdnsUpdate();
|
||||||
|
#endif // WEBSERVER_ADVERTISE
|
||||||
|
#endif // USE_WEBSERVER
|
||||||
|
#endif // USE_DISCOVERY
|
||||||
|
#endif // ESP8266
|
||||||
|
|
||||||
OsWatchLoop();
|
OsWatchLoop();
|
||||||
ButtonLoop();
|
ButtonLoop();
|
||||||
SwitchLoop();
|
SwitchLoop();
|
||||||
@ -444,6 +443,12 @@ void loop(void) {
|
|||||||
#ifdef USE_ARDUINO_OTA
|
#ifdef USE_ARDUINO_OTA
|
||||||
ArduinoOtaLoop();
|
ArduinoOtaLoop();
|
||||||
#endif // USE_ARDUINO_OTA
|
#endif // USE_ARDUINO_OTA
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(void) {
|
||||||
|
uint32_t my_sleep = millis();
|
||||||
|
|
||||||
|
Scheduler();
|
||||||
|
|
||||||
uint32_t my_activity = millis() - my_sleep;
|
uint32_t my_activity = millis() - my_sleep;
|
||||||
|
|
||||||
|
@ -365,13 +365,13 @@ ESP8266WebServer *Webserver;
|
|||||||
|
|
||||||
struct WEB {
|
struct WEB {
|
||||||
String chunk_buffer = ""; // Could be max 2 * CHUNKED_BUFFER_SIZE
|
String chunk_buffer = ""; // Could be max 2 * CHUNKED_BUFFER_SIZE
|
||||||
uint16_t upload_progress_dot_count;
|
|
||||||
uint16_t upload_error = 0;
|
uint16_t upload_error = 0;
|
||||||
uint8_t state = HTTP_OFF;
|
uint8_t state = HTTP_OFF;
|
||||||
uint8_t upload_file_type;
|
uint8_t upload_file_type;
|
||||||
uint8_t config_block_count = 0;
|
uint8_t config_block_count = 0;
|
||||||
uint8_t config_xor_on = 0;
|
uint8_t config_xor_on = 0;
|
||||||
uint8_t config_xor_on_set = CONFIG_FILE_XOR;
|
uint8_t config_xor_on_set = CONFIG_FILE_XOR;
|
||||||
|
bool upload_services_stopped = false;
|
||||||
bool reset_web_log_flag = false; // Reset web console log
|
bool reset_web_log_flag = false; // Reset web console log
|
||||||
} Web;
|
} Web;
|
||||||
|
|
||||||
@ -2298,14 +2298,8 @@ void HandleUploadDone(void) {
|
|||||||
|
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_UPLOAD_DONE));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_UPLOAD_DONE));
|
||||||
|
|
||||||
char error[100];
|
|
||||||
|
|
||||||
WifiConfigCounter();
|
WifiConfigCounter();
|
||||||
TasmotaGlobal.restart_flag = 0;
|
UploadServices(1);
|
||||||
MqttRetryCounter(0);
|
|
||||||
#ifdef USE_COUNTER
|
|
||||||
CounterInterruptDisable(false);
|
|
||||||
#endif // USE_COUNTER
|
|
||||||
|
|
||||||
WSContentStart_P(PSTR(D_INFORMATION));
|
WSContentStart_P(PSTR(D_INFORMATION));
|
||||||
if (!Web.upload_error) {
|
if (!Web.upload_error) {
|
||||||
@ -2315,6 +2309,7 @@ void HandleUploadDone(void) {
|
|||||||
WSContentSend_P(PSTR("<div style='text-align:center;'><b>" D_UPLOAD " <font color='#"));
|
WSContentSend_P(PSTR("<div style='text-align:center;'><b>" D_UPLOAD " <font color='#"));
|
||||||
if (Web.upload_error) {
|
if (Web.upload_error) {
|
||||||
WSContentSend_P(PSTR("%06x'>" D_FAILED "</font></b><br><br>"), WebColor(COL_TEXT_WARNING));
|
WSContentSend_P(PSTR("%06x'>" D_FAILED "</font></b><br><br>"), WebColor(COL_TEXT_WARNING));
|
||||||
|
char error[100];
|
||||||
if (Web.upload_error < 10) {
|
if (Web.upload_error < 10) {
|
||||||
GetTextIndexed(error, sizeof(error), Web.upload_error -1, kUploadErrors);
|
GetTextIndexed(error, sizeof(error), Web.upload_error -1, kUploadErrors);
|
||||||
} else {
|
} else {
|
||||||
@ -2323,6 +2318,7 @@ void HandleUploadDone(void) {
|
|||||||
WSContentSend_P(error);
|
WSContentSend_P(error);
|
||||||
DEBUG_CORE_LOG(PSTR("UPL: %s"), error);
|
DEBUG_CORE_LOG(PSTR("UPL: %s"), error);
|
||||||
TasmotaGlobal.stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
TasmotaGlobal.stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
||||||
|
Web.upload_error = 0;
|
||||||
} else {
|
} else {
|
||||||
WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "</font></b><br>"), WebColor(COL_TEXT_SUCCESS));
|
WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "</font></b><br>"), WebColor(COL_TEXT_SUCCESS));
|
||||||
TasmotaGlobal.restart_flag = 2; // Always restart to re-enable disabled features during update
|
TasmotaGlobal.restart_flag = 2; // Always restart to re-enable disabled features during update
|
||||||
@ -2335,14 +2331,65 @@ void HandleUploadDone(void) {
|
|||||||
WSContentStop();
|
WSContentStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UploadServices(uint32_t start_service) {
|
||||||
|
if (Web.upload_services_stopped == start_service) { return; }
|
||||||
|
Web.upload_services_stopped = start_service;
|
||||||
|
|
||||||
|
if (start_service) {
|
||||||
|
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("UPL: Services enabled"));
|
||||||
|
|
||||||
|
TasmotaGlobal.restart_flag = 0;
|
||||||
|
/*
|
||||||
|
MqttRetryCounter(0);
|
||||||
|
*/
|
||||||
|
#ifdef USE_ARILUX_RF
|
||||||
|
AriluxRfInit();
|
||||||
|
#endif // USE_ARILUX_RF
|
||||||
|
#ifdef USE_COUNTER
|
||||||
|
CounterInterruptDisable(false);
|
||||||
|
#endif // USE_COUNTER
|
||||||
|
#ifdef USE_EMULATION
|
||||||
|
UdpConnect();
|
||||||
|
#endif // USE_EMULATION
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("UPL: Services disabled"));
|
||||||
|
|
||||||
|
#ifdef USE_EMULATION
|
||||||
|
UdpDisconnect();
|
||||||
|
#endif // USE_EMULATION
|
||||||
|
#ifdef USE_COUNTER
|
||||||
|
CounterInterruptDisable(true); // Prevent OTA failures on 100Hz counter interrupts
|
||||||
|
#endif // USE_COUNTER
|
||||||
|
#ifdef USE_ARILUX_RF
|
||||||
|
AriluxRfDisable(); // Prevent restart exception on Arilux Interrupt routine
|
||||||
|
#endif // USE_ARILUX_RF
|
||||||
|
/*
|
||||||
|
MqttRetryCounter(60);
|
||||||
|
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||||
|
MqttDisconnect();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
TasmotaGlobal.restart_flag = 120; // Set restart watchdog after 2 minutes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HandleUploadLoop(void) {
|
void HandleUploadLoop(void) {
|
||||||
// Based on ESP8266HTTPUpdateServer.cpp uses ESP8266WebServer Parsing.cpp and Cores Updater.cpp (Update)
|
// Based on ESP8266HTTPUpdateServer.cpp uses ESP8266WebServer Parsing.cpp and Cores Updater.cpp (Update)
|
||||||
static uint32_t upload_size;
|
static uint32_t upload_size;
|
||||||
bool _serialoutput = (LOG_LEVEL_DEBUG <= TasmotaGlobal.seriallog_level);
|
static bool upload_error_signalled;
|
||||||
|
|
||||||
if (HTTP_USER == Web.state) { return; }
|
if (HTTP_USER == Web.state) { return; }
|
||||||
|
|
||||||
if (Web.upload_error) {
|
if (Web.upload_error) {
|
||||||
if (UPL_TASMOTA == Web.upload_file_type) { Update.end(); }
|
if (!upload_error_signalled) {
|
||||||
|
if (UPL_TASMOTA == Web.upload_file_type) { Update.end(); }
|
||||||
|
UploadServices(1);
|
||||||
|
|
||||||
|
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "Upload error %d"), Web.upload_error);
|
||||||
|
|
||||||
|
upload_error_signalled = true;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2351,15 +2398,18 @@ void HandleUploadLoop(void) {
|
|||||||
// ***** Step1: Start upload file
|
// ***** Step1: Start upload file
|
||||||
if (UPLOAD_FILE_START == upload.status) {
|
if (UPLOAD_FILE_START == upload.status) {
|
||||||
Web.upload_error = 0;
|
Web.upload_error = 0;
|
||||||
|
upload_error_signalled = false;
|
||||||
upload_size = 0;
|
upload_size = 0;
|
||||||
TasmotaGlobal.restart_flag = 60;
|
|
||||||
|
UploadServices(0);
|
||||||
|
|
||||||
if (0 == upload.filename.c_str()[0]) {
|
if (0 == upload.filename.c_str()[0]) {
|
||||||
Web.upload_error = 1; // No file selected
|
Web.upload_error = 1; // No file selected
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SettingsSave(1); // Free flash for upload
|
SettingsSave(1); // Free flash for upload
|
||||||
|
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPLOAD D_FILE " %s ..."), upload.filename.c_str());
|
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPLOAD D_FILE " %s"), upload.filename.c_str());
|
||||||
|
|
||||||
if (UPL_SETTINGS == Web.upload_file_type) {
|
if (UPL_SETTINGS == Web.upload_file_type) {
|
||||||
if (!SettingsBufferAlloc()) {
|
if (!SettingsBufferAlloc()) {
|
||||||
@ -2376,22 +2426,6 @@ void HandleUploadLoop(void) {
|
|||||||
TasmotaGlobal.restart_flag = 0;
|
TasmotaGlobal.restart_flag = 0;
|
||||||
}
|
}
|
||||||
#endif // USE_UFILESYS
|
#endif // USE_UFILESYS
|
||||||
else {
|
|
||||||
MqttRetryCounter(60);
|
|
||||||
#ifdef USE_COUNTER
|
|
||||||
CounterInterruptDisable(true); // Prevent OTA failures on 100Hz counter interrupts
|
|
||||||
#endif // USE_COUNTER
|
|
||||||
#ifdef USE_EMULATION
|
|
||||||
UdpDisconnect();
|
|
||||||
#endif // USE_EMULATION
|
|
||||||
#ifdef USE_ARILUX_RF
|
|
||||||
AriluxRfDisable(); // Prevent restart exception on Arilux Interrupt routine
|
|
||||||
#endif // USE_ARILUX_RF
|
|
||||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
|
||||||
MqttDisconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Web.upload_progress_dot_count = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***** Step2: Write upload file
|
// ***** Step2: Write upload file
|
||||||
@ -2487,21 +2521,14 @@ void HandleUploadLoop(void) {
|
|||||||
Web.upload_error = 5; // Upload buffer miscompare
|
Web.upload_error = 5; // Upload buffer miscompare
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_serialoutput) {
|
if (upload.totalSize && !(upload.totalSize % 102400)) {
|
||||||
upload_size += upload.currentSize;
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "Progress %dkB"), upload.totalSize / 1024);
|
||||||
Serial.printf(".");
|
|
||||||
Web.upload_progress_dot_count++;
|
|
||||||
if (!(Web.upload_progress_dot_count % 50)) { // Assuming core HTTP_UPLOAD_BUFLEN=2048
|
|
||||||
Serial.printf("%5dkB\n", upload_size / 1024);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***** Step3: Finish upload file
|
// ***** Step3: Finish upload file
|
||||||
else if (UPLOAD_FILE_END == upload.status) {
|
else if (UPLOAD_FILE_END == upload.status) {
|
||||||
if (_serialoutput && (Web.upload_progress_dot_count % 50)) {
|
UploadServices(1);
|
||||||
Serial.printf("%5dkB\n", upload_size / 1024);
|
|
||||||
}
|
|
||||||
if (UPL_SETTINGS == Web.upload_file_type) {
|
if (UPL_SETTINGS == Web.upload_file_type) {
|
||||||
if (Web.config_xor_on_set) {
|
if (Web.config_xor_on_set) {
|
||||||
for (uint32_t i = 2; i < sizeof(Settings); i++) {
|
for (uint32_t i = 2; i < sizeof(Settings); i++) {
|
||||||
@ -2593,7 +2620,6 @@ void HandleUploadLoop(void) {
|
|||||||
}
|
}
|
||||||
#endif // USE_WEB_FW_UPGRADE
|
#endif // USE_WEB_FW_UPGRADE
|
||||||
else if (!Update.end(true)) { // true to set the size to the current progress
|
else if (!Update.end(true)) { // true to set the size to the current progress
|
||||||
if (_serialoutput) { Update.printError(Serial); }
|
|
||||||
Web.upload_error = 6; // Upload failed. Enable logging 3
|
Web.upload_error = 6; // Upload failed. Enable logging 3
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2601,18 +2627,13 @@ void HandleUploadLoop(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ***** Step4: Abort upload file
|
// ***** Step4: Abort upload file
|
||||||
// else if (UPLOAD_FILE_ABORTED == upload.status) {
|
|
||||||
else {
|
else {
|
||||||
TasmotaGlobal.restart_flag = 0;
|
UploadServices(1);
|
||||||
MqttRetryCounter(0);
|
|
||||||
#ifdef USE_COUNTER
|
|
||||||
CounterInterruptDisable(false);
|
|
||||||
#endif // USE_COUNTER
|
|
||||||
Web.upload_error = 7; // Upload aborted
|
Web.upload_error = 7; // Upload aborted
|
||||||
if (UPL_TASMOTA == Web.upload_file_type) { Update.end(); }
|
if (UPL_TASMOTA == Web.upload_file_type) { Update.end(); }
|
||||||
}
|
}
|
||||||
delay(0);
|
delay(0);
|
||||||
OsWatchLoop(); // Feed OsWatch timer to prevent restart on long uploads
|
Scheduler(); // Feed OsWatch timer to prevent restart on long uploads
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------------------*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user