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