diff --git a/src/svc/hasp_http.cpp b/src/svc/hasp_http.cpp
index bbda1e2c..e1218a38 100644
--- a/src/svc/hasp_http.cpp
+++ b/src/svc/hasp_http.cpp
@@ -5,7 +5,6 @@
#include "ArduinoJson.h"
#include "ArduinoLog.h"
#include "lvgl.h"
-#include "StringStream.h"
#if defined(ARDUINO_ARCH_ESP32)
#include "Update.h"
@@ -18,6 +17,7 @@
#include "hasp_debug.h"
#include "hasp_config.h"
+#include "hasp/hasp_utilities.h"
#include "hasp/hasp_dispatch.h"
#include "hasp/hasp.h"
@@ -49,12 +49,15 @@ EthernetWebServer webServer(80);
#endif
#if defined(ARDUINO_ARCH_ESP8266)
+ #include "StringStream.h"
#include ");
@@ -485,16 +489,19 @@ void webHandleInfo()
httpMessage += F("s");
httpMessage += F("
Free Memory: ");
- httpMessage += halFormatBytes(halGetFreeHeap());
+ hasp_util_format_bytes(halGetFreeHeap(), size_buf, sizeof(size_buf));
+ httpMessage += size_buf;
httpMessage += F("
Memory Fragmentation: ");
httpMessage += String(halGetHeapFragmentation());
#if ARDUINO_ARCH_ESP32
if(psramFound()) {
httpMessage += F("
Free PSRam: ");
- httpMessage += halFormatBytes(ESP.getFreePsram());
+ hasp_util_format_bytes(ESP.getFreePsram(), size_buf, sizeof(size_buf));
+ httpMessage += size_buf;
httpMessage += F("
PSRam Size: ");
- httpMessage += halFormatBytes(ESP.getPsramSize());
+ hasp_util_format_bytes(ESP.getPsramSize(), size_buf, sizeof(size_buf));
+ httpMessage += size_buf;
}
#endif
@@ -502,9 +509,11 @@ void webHandleInfo()
lv_mem_monitor_t mem_mon;
lv_mem_monitor(&mem_mon);
httpMessage += F("
LVGL Memory: ");
- httpMessage += halFormatBytes(mem_mon.total_size);
+ hasp_util_format_bytes(mem_mon.total_size, size_buf, sizeof(size_buf));
+ httpMessage += size_buf;
httpMessage += F("
LVGL Free: ");
- httpMessage += halFormatBytes(mem_mon.free_size);
+ hasp_util_format_bytes(mem_mon.free_size, size_buf, sizeof(size_buf));
+ httpMessage += size_buf;
httpMessage += F("
LVGL Fragmentation: ");
httpMessage += mem_mon.frag_pct;
@@ -602,14 +611,20 @@ void webHandleInfo()
httpMessage += halGetChipModel();
httpMessage += F("
CPU Frequency: ");
httpMessage += String(halGetCpuFreqMHz());
+ httpMessage += F("MHz");
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
- httpMessage += F("MHz
Flash Chip Size: ");
- httpMessage += halFormatBytes(ESP.getFlashChipSize());
+ httpMessage += F("
Flash Chip Size: ");
+ hasp_util_format_bytes(ESP.getFlashChipSize(), size_buf, sizeof(size_buf));
+ httpMessage += size_buf;
+
httpMessage += F("Program Size: ");
- httpMessage += halFormatBytes(ESP.getSketchSize());
+ hasp_util_format_bytes(ESP.getSketchSize(), size_buf, sizeof(size_buf));
+ httpMessage += size_buf;
+
httpMessage += F("
Free Program Space: ");
- httpMessage += halFormatBytes(ESP.getFreeSketchSpace());
+ hasp_util_format_bytes(ESP.getFreeSketchSpace(), size_buf, sizeof(size_buf));
+ httpMessage += size_buf;
#endif
//#if defined(ARDUINO_ARCH_ESP32)
@@ -631,34 +646,50 @@ void webHandleInfo()
webSendFooter();
}
-String getContentType(String filename)
+// String getContentType(String filename)
+// {
+// if(webServer.hasArg(F("download"))) {
+// return F("application/octet-stream");
+// } else if(filename.endsWith(F(".htm")) || filename.endsWith(F(".html"))) {
+// return F("text/html");
+// } else if(filename.endsWith(F(".css"))) {
+// return F("text/css");
+// } else if(filename.endsWith(F(".js"))) {
+// return F("application/javascript");
+// } else if(filename.endsWith(F(".png"))) {
+// return F("image/png");
+// } else if(filename.endsWith(F(".gif"))) {
+// return F("image/gif");
+// } else if(filename.endsWith(F(".jpg"))) {
+// return F("image/jpeg");
+// } else if(filename.endsWith(F(".ico"))) {
+// return F("image/x-icon");
+// } else if(filename.endsWith(F(".xml"))) {
+// return F("text/xml");
+// } else if(filename.endsWith(F(".pdf"))) {
+// return F("application/x-pdf");
+// } else if(filename.endsWith(F(".zip"))) {
+// return F("application/x-zip");
+// } else if(filename.endsWith(F(".gz"))) {
+// return F("application/x-gzip");
+// }
+// return F("text/plain");
+// }
+
+static String getContentType(const String & path)
{
- if(webServer.hasArg(F("download"))) {
- return F("application/octet-stream");
- } else if(filename.endsWith(F(".htm")) || filename.endsWith(F(".html"))) {
- return F("text/html");
- } else if(filename.endsWith(F(".css"))) {
- return F("text/css");
- } else if(filename.endsWith(F(".js"))) {
- return F("application/javascript");
- } else if(filename.endsWith(F(".png"))) {
- return F("image/png");
- } else if(filename.endsWith(F(".gif"))) {
- return F("image/gif");
- } else if(filename.endsWith(F(".jpg"))) {
- return F("image/jpeg");
- } else if(filename.endsWith(F(".ico"))) {
- return F("image/x-icon");
- } else if(filename.endsWith(F(".xml"))) {
- return F("text/xml");
- } else if(filename.endsWith(F(".pdf"))) {
- return F("application/x-pdf");
- } else if(filename.endsWith(F(".zip"))) {
- return F("application/x-zip");
- } else if(filename.endsWith(F(".gz"))) {
- return F("application/x-gzip");
+ char buff[sizeof(mime::mimeTable[0].mimeType)];
+ // Check all entries but last one for match, return if found
+ for(size_t i = 0; i < sizeof(mime::mimeTable) / sizeof(mime::mimeTable[0]) - 1; i++) {
+ strcpy_P(buff, mime::mimeTable[i].endsWith);
+ if(path.endsWith(buff)) {
+ strcpy_P(buff, mime::mimeTable[i].mimeType);
+ return String(buff);
+ }
}
- return F("text/plain");
+ // Fall-through and just return default type
+ strcpy_P(buff, mime::mimeTable[sizeof(mime::mimeTable) / sizeof(mime::mimeTable[0]) - 1].mimeType);
+ return String(buff);
}
/* String urldecode(String str)
@@ -700,14 +731,19 @@ void webUploadProgress()
}
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
-void webUpdatePrintError()
+static inline void webUpdatePrintError()
{
+ #if defined(ARDUINO_ARCH_ESP8266)
String output((char *)0);
output.reserve(128);
StringStream stream((String &)output);
- Update.printError(stream);
+ Update.printError(stream); // ESP8266 only has printError()
Log.error(TAG_HTTP, output.c_str());
haspProgressMsg(output.c_str());
+ #elif defined(ARDUINO_ARCH_ESP32)
+ Log.error(TAG_HTTP, Update.errorString()); // ESP32 has errorString()
+ haspProgressMsg(Update.errorString());
+ #endif
}
void webUpdateReboot()
@@ -732,9 +768,10 @@ void webUpdateReboot()
dispatch_reboot(true); // Save the current config
}
-void webHandleFirmwareUpdate()
+void webHandleFirmwareUpload()
{
upload = &webServer.upload();
+
if(upload->status == UPLOAD_FILE_START) {
if(!httpIsAuthenticated(F("update"))) return;
Log.notice(TAG_HTTP, F("Update: %s"), upload->filename.c_str());
@@ -745,6 +782,7 @@ void webHandleFirmwareUpdate()
if(!Update.begin(maxSketchSpace)) { // start with max available size
webUpdatePrintError();
}
+
} else if(upload->status == UPLOAD_FILE_WRITE) {
// flashing firmware to ESP
if(Update.write(upload->buf, upload->currentSize) != upload->currentSize) {
@@ -752,6 +790,7 @@ void webHandleFirmwareUpdate()
} else {
webUploadProgress();
}
+
} else if(upload->status == UPLOAD_FILE_END) {
haspProgressVal(100);
if(Update.end(true)) { // true to set the size to the current progress
@@ -1204,28 +1243,49 @@ void webHandleHttpConfig()
StaticJsonDocument<256> settings;
httpGetConfig(settings.to");
- httpMessage += httpGetNodename();
- httpMessage += F("
");
+ // String httpMessage((char *)0);
+ // httpMessage.reserve(HTTP_PAGE_SIZE);
+ // httpMessage += F("");
+ // httpMessage += httpGetNodename();
+ // httpMessage += F("
");
- httpMessage += F("");
+ // httpMessage += F("");
- httpMessage += PSTR("