mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Add progress bar to GUI
This commit is contained in:
parent
1f47c96e19
commit
01bbcaf256
@ -45,7 +45,7 @@ char httpUser[32] = "";
|
||||
char httpPassword[32] = "";
|
||||
#define HTTP_PAGE_SIZE (6 * 256)
|
||||
|
||||
#if defined(STM32F4xx) && HASP_USE_ETHERNET>0
|
||||
#if defined(STM32F4xx) && HASP_USE_ETHERNET > 0
|
||||
#include <EthernetWebServer_STM32.h>
|
||||
EthernetWebServer webServer(80);
|
||||
#endif
|
||||
@ -603,10 +603,13 @@ String getContentType(String filename)
|
||||
static unsigned long htppLastLoopTime = 0;
|
||||
void webUploadProgress()
|
||||
{
|
||||
long t = webServer.header("Content-Length").toInt();
|
||||
if(millis() - htppLastLoopTime >= 1250) {
|
||||
Log.verbose(F(" * Uploaded %u bytes"), upload->totalSize + upload->currentSize);
|
||||
Log.verbose(F(" * Uploaded %u bytes / %d"), upload->totalSize + upload->currentSize, t);
|
||||
htppLastLoopTime = millis();
|
||||
}
|
||||
if(t > 0) t = (upload->totalSize + upload->currentSize) * 100 / t;
|
||||
haspProgressVal(t);
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||
@ -617,6 +620,7 @@ void webUpdatePrintError()
|
||||
StringStream stream((String &)output);
|
||||
Update.printError(stream);
|
||||
Log.error(F("HTTP: %s"), output.c_str());
|
||||
haspProgressMsg(output.c_str());
|
||||
}
|
||||
|
||||
void webUpdateReboot()
|
||||
@ -648,6 +652,7 @@ void webHandleFirmwareUpdate()
|
||||
if(upload->status == UPLOAD_FILE_START) {
|
||||
if(!httpIsAuthenticated(F("update"))) return;
|
||||
Log.notice(F("Update: %s"), upload->filename.c_str());
|
||||
haspProgressMsg(upload->filename.c_str());
|
||||
// WiFiUDP::stopAll();
|
||||
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
// if(!Update.begin(UPDATE_SIZE_UNKNOWN)) { // start with max available size
|
||||
@ -704,6 +709,7 @@ void handleFileUpload()
|
||||
upload = &webServer.upload();
|
||||
if(upload->status == UPLOAD_FILE_START) {
|
||||
if(!httpIsAuthenticated(F("fileupload"))) return;
|
||||
Log.verbose(F("Total size: %s"), webServer.headerName(0).c_str());
|
||||
String filename((char *)0);
|
||||
filename.reserve(128);
|
||||
filename = upload->filename;
|
||||
@ -714,6 +720,7 @@ void handleFileUpload()
|
||||
if(filename.length() < 32) {
|
||||
fsUploadFile = filesystem->open(filename, "w");
|
||||
Log.notice(F("handleFileUpload Name: %s"), filename.c_str());
|
||||
haspProgressMsg(fsUploadFile.name());
|
||||
} else {
|
||||
Log.error(F("Filename %s is too long"), filename.c_str());
|
||||
}
|
||||
@ -731,6 +738,7 @@ void handleFileUpload()
|
||||
Log.verbose(F("Uploaded %s (%u bytes)"), fsUploadFile.name(), upload->totalSize);
|
||||
fsUploadFile.close();
|
||||
}
|
||||
haspProgressVal(255);
|
||||
|
||||
// Redirect to /config/hasp page. This flushes the web buffer and frees the memory
|
||||
webServer.sendHeader(String(F("Location")), String(F("/config/hasp")), true);
|
||||
@ -1552,7 +1560,12 @@ void httpSetup()
|
||||
// first callback is called after the request has ended with all parsed arguments
|
||||
// second callback handles file uploads at that location
|
||||
webServer.on(
|
||||
F("/edit"), HTTP_POST, []() { webServer.send(200, "text/plain", ""); }, handleFileUpload);
|
||||
F("/edit"), HTTP_POST,
|
||||
[]() {
|
||||
webServer.send(200, "text/plain", "");
|
||||
Log.verbose(F("Headers: %d"), webServer.headers());
|
||||
},
|
||||
handleFileUpload);
|
||||
#endif
|
||||
|
||||
// get heap status, analog input value and all GPIO statuses in one json call
|
||||
@ -1593,7 +1606,12 @@ void httpSetup()
|
||||
webServer.on(F("/firmware"), webHandleFirmware);
|
||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||
webServer.on(
|
||||
F("/update"), HTTP_POST, []() { webServer.send(200, "text/plain", ""); }, webHandleFirmwareUpdate);
|
||||
F("/update"), HTTP_POST,
|
||||
[]() {
|
||||
webServer.send(200, "text/plain", "");
|
||||
Log.verbose(F("Total size: %s"), webServer.hostHeader().c_str());
|
||||
},
|
||||
webHandleFirmwareUpdate);
|
||||
webServer.on(F("/espfirmware"), httpHandleEspFirmware);
|
||||
#endif
|
||||
webServer.on(F("/reboot"), httpHandleReboot);
|
||||
@ -1607,6 +1625,11 @@ void httpSetup()
|
||||
webServer.on(F("/config"), webHandleConfig);
|
||||
webServer.onNotFound(httpHandleNotFound);
|
||||
|
||||
// ask server to track these headers
|
||||
const char * headerkeys[] = {"Content-Length"}; // "Authentication"
|
||||
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *);
|
||||
webServer.collectHeaders(headerkeys, headerkeyssize);
|
||||
|
||||
Log.verbose(F("HTTP: Setup Complete"));
|
||||
webStart();
|
||||
}
|
||||
|
@ -7,14 +7,15 @@
|
||||
#include "hasp_debug.h"
|
||||
#include "hasp_dispatch.h"
|
||||
#include "hasp_ota.h"
|
||||
#include "hasp.h"
|
||||
|
||||
#include "hasp_conf.h"
|
||||
|
||||
#if HASP_USE_MQTT>0
|
||||
#if HASP_USE_MQTT > 0
|
||||
#include "hasp_mqtt.h"
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MDNS>0
|
||||
#if HASP_USE_MDNS > 0
|
||||
#include "hasp_mdns.h"
|
||||
#endif
|
||||
|
||||
@ -56,20 +57,28 @@ void otaSetup()
|
||||
}
|
||||
|
||||
Log.notice(F("OTA: Start update"));
|
||||
haspProgressVal(0);
|
||||
haspProgressMsg(F("OTA: Firmware Update"));
|
||||
// dispatchPage("0");
|
||||
otaPrecentageComplete = 0;
|
||||
// haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\"");
|
||||
});
|
||||
ArduinoOTA.onEnd([]() {
|
||||
otaPrecentageComplete = 100;
|
||||
haspProgressMsg(F("Applying Firmware & Reboot"));
|
||||
haspProgressVal(100);
|
||||
otaProgress();
|
||||
otaPrecentageComplete = -1;
|
||||
// dispatchPage("0");
|
||||
// haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\\rComplete!\"");
|
||||
dispatchReboot(true);
|
||||
setup();
|
||||
//dispatchReboot(true);
|
||||
});
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
if(total != 0) otaPrecentageComplete = progress * 100 / total;
|
||||
if(total != 0) {
|
||||
otaPrecentageComplete = progress * 100 / total;
|
||||
haspProgressVal(otaPrecentageComplete);
|
||||
}
|
||||
|
||||
// haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\\rProgress: " + String(progress / (total / 100)) + "%\"");
|
||||
});
|
||||
@ -87,7 +96,7 @@ void otaSetup()
|
||||
else if(error == OTA_END_ERROR)
|
||||
Log.error(F("OTA: ERROR - End Failed"));
|
||||
// haspSetAttr("p[0].b[1].txt", "\"ESP OTA FAILED\"");
|
||||
delay(5000);
|
||||
// delay(5000);
|
||||
// haspSendCmd("page " + String(nextionActivePage));
|
||||
});
|
||||
|
||||
@ -107,7 +116,7 @@ void otaSetup()
|
||||
#endif
|
||||
// ArduinoOTA.setTimeout(1000);
|
||||
#endif
|
||||
ArduinoOTA.setRebootOnSuccess(true);
|
||||
ArduinoOTA.setRebootOnSuccess(false); // We do that
|
||||
|
||||
ArduinoOTA.begin();
|
||||
Log.notice(F("OTA: Over the Air firmware update ready"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user