diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp
index f6816db2c..8dabd6524 100644
--- a/src/hasp_http.cpp
+++ b/src/hasp_http.cpp
@@ -8,7 +8,7 @@
#include "StringStream.h"
#if defined(ARDUINO_ARCH_ESP32)
-#include "Update.h"
+ #include "Update.h"
#endif
#include "hasp_conf.h"
@@ -26,34 +26,34 @@ bool httpEnable = true;
bool webServerStarted = false;
uint16_t httpPort = 80;
-#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
+ #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
File fsUploadFile;
-#endif
+ #endif
char httpUser[32] = "";
char httpPassword[32] = "";
-#define HTTP_PAGE_SIZE (6 * 256)
+ #define HTTP_PAGE_SIZE (6 * 256)
-#if defined(STM32F4xx) && HASP_USE_ETHERNET > 0
-#include
SSID: "); httpMessage += String(WiFi.SSID()); httpMessage += F("Signal Strength: "); @@ -487,7 +487,7 @@ void webHandleInfo() } else { httpMessage += F("Very Bad)"); } -#if defined(STM32F4xx) + #if defined(STM32F4xx) byte mac[6]; WiFi.macAddress(mac); char macAddress[16]; @@ -499,7 +499,7 @@ void webHandleInfo() httpMessage += String(WiFi.gatewayIP()); httpMessage += F("MAC Address: "); httpMessage += String(macAddress); -#else + #else httpMessage += F("IP Address: "); httpMessage += String(WiFi.localIP().toString()); httpMessage += F("Gateway: "); @@ -508,10 +508,10 @@ void webHandleInfo() httpMessage += String(WiFi.dnsIP().toString()); httpMessage += F("MAC Address: "); httpMessage += String(WiFi.macAddress()); -#endif -#endif -#if HASP_USE_ETHERNET > 0 -#if defined(ARDUINO_ARCH_ESP32) + #endif + #endif + #if HASP_USE_ETHERNET > 0 + #if defined(ARDUINO_ARCH_ESP32) httpMessage += F("
Ethernet: "); httpMessage += String(ETH.linkSpeed()); httpMessage += F(" Mbps"); @@ -526,10 +526,10 @@ void webHandleInfo() httpMessage += String(ETH.dnsIP().toString()); httpMessage += F("MAC Address: "); httpMessage += String(ETH.macAddress()); -#endif -#endif -/* Mqtt Stats */ -#if HASP_USE_MQTT > 0 + #endif + #endif + /* Mqtt Stats */ + #if HASP_USE_MQTT > 0 httpMessage += F("
MQTT Status: "); if(mqttIsConnected()) { // Check MQTT connection httpMessage += F("Connected"); @@ -547,7 +547,7 @@ void webHandleInfo() httpMessage += mqttClientId; } -#endif // MQTT + #endif // MQTT /* ESP Stats */ httpMessage += F("
MCU Model: ");
@@ -555,14 +555,14 @@ void webHandleInfo()
httpMessage += F("
CPU Frequency: ");
httpMessage += String(halGetCpuFreqMHz());
-#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
+ #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
httpMessage += F("MHz
Flash Chip Size: ");
httpMessage += halFormatBytes(ESP.getFlashChipSize());
httpMessage += F("Program Size: ");
httpMessage += halFormatBytes(ESP.getSketchSize());
httpMessage += F("
Free Program Space: ");
httpMessage += halFormatBytes(ESP.getFreeSketchSpace());
-#endif
+ #endif
//#if defined(ARDUINO_ARCH_ESP32)
// httpMessage += F("
ESP SDK version: ");
@@ -651,7 +651,7 @@ void webUploadProgress()
haspProgressVal(t);
}
-#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
+ #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
void webUpdatePrintError()
{
String output((char *)0);
@@ -714,9 +714,9 @@ void webHandleFirmwareUpdate()
}
}
}
-#endif
+ #endif
-#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
+ #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
bool handleFileRead(String path)
{
if(!httpIsAuthenticated(F("fileread"))) return false;
@@ -848,7 +848,7 @@ void handleFileList()
Log.notice(TAG_HTTP, F("handleFileList: %s"), path.c_str());
path.clear();
-#if defined(ARDUINO_ARCH_ESP32)
+ #if defined(ARDUINO_ARCH_ESP32)
File root = HASP_FS.open("/", FILE_READ);
File file = root.openNextFile();
String output = "[";
@@ -873,7 +873,7 @@ void handleFileList()
}
output += "]";
webServer.send(200, PSTR("text/json"), output);
-#elif defined(ARDUINO_ARCH_ESP8266)
+ #elif defined(ARDUINO_ARCH_ESP8266)
Dir dir = HASP_FS.openDir(path);
String output = "[";
while(dir.next()) {
@@ -895,9 +895,9 @@ void handleFileList()
}
output += "]";
webServer.send(200, PSTR("text/json"), output);
-#endif
+ #endif
}
-#endif
+ #endif
////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleConfig()
@@ -914,10 +914,10 @@ void webHandleConfig()
if(save == String(PSTR("hasp"))) {
haspSetConfig(settings.as
");
-#if HASP_USE_WIFI > 0
+ #if HASP_USE_WIFI > 0
httpMessage +=
F("
Backlight Control
"); httpMessage += F(""); @@ -1124,8 +1124,8 @@ void webHandleGuiConfig() if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); } -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if HASP_USE_WIFI > 0 + //////////////////////////////////////////////////////////////////////////////////////////////////// + #if HASP_USE_WIFI > 0 void webHandleWifiConfig() { // http://plate01/config/wifi if(!httpIsAuthenticated(F("config/wifi"))) return; @@ -1150,26 +1150,26 @@ void webHandleWifiConfig() } httpMessage += F("'>"); -#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) + #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) if(WiFi.getMode() == WIFI_STA) { httpMessage += PSTR(""); } -#endif + #endif webSendPage(httpGetNodename(), httpMessage.length(), false); webServer.sendContent(httpMessage); -#if defined(STM32F4xx) + #if defined(STM32F4xx) httpMessage = ""; -#else + #else httpMessage.clear(); -#endif + #endif webSendFooter(); } -#endif + #endif -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if HASP_USE_HTTP > 0 + //////////////////////////////////////////////////////////////////////////////////////////////////// + #if HASP_USE_HTTP > 0 void webHandleHttpConfig() { // http://plate01/config/http if(!httpIsAuthenticated(F("config/http"))) return; @@ -1204,10 +1204,10 @@ void webHandleHttpConfig() // httpMessage.clear(); webSendFooter(); } -#endif + #endif -//////////////////////////////////////////////////////////////////////////////////////////////////// -#if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) + //////////////////////////////////////////////////////////////////////////////////////////////////// + #if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) void webHandleGpioConfig() { // http://plate01/config/gpio if(!httpIsAuthenticated(F("config/gpio"))) return; @@ -1224,6 +1224,11 @@ void webHandleGpioConfig() uint8_t pinfunc = webServer.arg(F("func")).toInt(); gpioSavePinConfig(id, pin, type, group, pinfunc); } + if(webServer.hasArg(PSTR("del"))) { + uint8_t id = webServer.arg(F("id")).toInt(); + uint8_t pin = webServer.arg(F("pin")).toInt(); + gpioSavePinConfig(id, pin, HASP_GPIO_FREE, 0, 0); + } { String httpMessage((char *)0); @@ -1284,8 +1289,10 @@ void webHandleGpioConfig() httpMessage += F("Default Font
"); httpMessage += F("Startup Layout (optional) 0 || HASP_USE_LITTLEFS > 0 + #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 if(handleFileRead(webServer.uri())) return; -#endif + #endif -#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) Log.notice(TAG_HTTP, F("Sending 404 to client connected from: %s"), webServer.client().remoteIP().toString().c_str()); -#else + #else // Log.notice(TAG_HTTP,F("Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); -#endif + #endif String httpMessage((char *)0); httpMessage.reserve(HTTP_PAGE_SIZE); @@ -1723,24 +1730,24 @@ void httpStart() { webServer.begin(); webServerStarted = true; -#if HASP_USE_WIFI > 0 -#if defined(STM32F4xx) + #if HASP_USE_WIFI > 0 + #if defined(STM32F4xx) IPAddress ip; ip = WiFi.localIP(); Log.trace(TAG_HTTP, F("Server started @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); -#else + #else Log.trace(TAG_HTTP, F("Server started @ http://%s"), (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str())); -#endif -#else + #endif + #else IPAddress ip; -#if defined(ARDUINO_ARCH_ESP32) + #if defined(ARDUINO_ARCH_ESP32) ip = ETH.localIP(); -#else + #else ip = Ethernet.localIP(); -#endif + #endif Log.trace(TAG_HTTP, F("Server started @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); -#endif + #endif } void httpStop() @@ -1755,14 +1762,14 @@ void httpSetup() { // httpSetConfig(settings); -#if HASP_USE_WIFI > 0 -#if !defined(STM32F4xx) + #if HASP_USE_WIFI > 0 + #if !defined(STM32F4xx) if(WiFi.getMode() != WIFI_STA) { Log.notice(TAG_HTTP, F("Wifi access point")); webServer.on(F("/"), webHandleWifiConfig); } else { -#endif -#endif + #endif + #endif webServer.on(F("/page/"), []() { String pageid = webServer.arg(F("page")); @@ -1770,7 +1777,7 @@ void httpSetup() haspSetPage(pageid.toInt()); }); -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 + #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 webServer.on(F("/list"), HTTP_GET, handleFileList); // load editor webServer.on(F("/edit"), HTTP_GET, []() { @@ -1791,7 +1798,7 @@ void httpSetup() Log.verbose(TAG_HTTP, F("Headers: %d"), webServer.headers()); }, handleFileUpload); -#endif + #endif // get heap status, analog input value and all GPIO statuses in one json call /*webServer.on(F("/all"), HTTP_GET, []() { @@ -1816,21 +1823,21 @@ void httpSetup() webServer.on(F("/config/http"), webHandleHttpConfig); webServer.on(F("/config/gui"), webHandleGuiConfig); webServer.on(F("/config/debug"), webHandleDebugConfig); -#if HASP_USE_MQTT > 0 + #if HASP_USE_MQTT > 0 webServer.on(F("/config/mqtt"), webHandleMqttConfig); -#endif -#if HASP_USE_WIFI > 0 + #endif + #if HASP_USE_WIFI > 0 webServer.on(F("/config/wifi"), webHandleWifiConfig); -#endif -#if HASP_USE_GPIO > 0 + #endif + #if HASP_USE_GPIO > 0 webServer.on(F("/config/gpio"), webHandleGpioConfig); webServer.on(F("/config/gpio/options"), webHandleGpioOptions); -#endif + #endif webServer.on(F("/screenshot"), webHandleScreenshot); webServer.on(F("/saveConfig"), webHandleSaveConfig); webServer.on(F("/resetConfig"), httpHandleResetConfig); 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( F("/update"), HTTP_POST, []() { @@ -1839,14 +1846,14 @@ void httpSetup() }, webHandleFirmwareUpdate); webServer.on(F("/espfirmware"), httpHandleEspFirmware); -#endif + #endif webServer.on(F("/reboot"), httpHandleReboot); webServer.onNotFound(httpHandleNotFound); -#if HASP_USE_WIFI > 0 -#if !defined(STM32F4xx) + #if HASP_USE_WIFI > 0 + #if !defined(STM32F4xx) } -#endif -#endif + #endif + #endif // Shared pages webServer.on(F("/about"), webHandleAbout); @@ -1870,9 +1877,9 @@ void httpReconnect() if(webServerStarted) { httpStop(); } else -#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) + #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA) -#endif + #endif { httpStart(); }