Add delete GPIO config

This commit is contained in:
fvanroie 2020-12-19 03:05:55 +01:00
parent c04b64eee4
commit 929a4a5041

View File

@ -8,7 +8,7 @@
#include "StringStream.h" #include "StringStream.h"
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#include "Update.h" #include "Update.h"
#endif #endif
#include "hasp_conf.h" #include "hasp_conf.h"
@ -26,34 +26,34 @@ bool httpEnable = true;
bool webServerStarted = false; bool webServerStarted = false;
uint16_t httpPort = 80; uint16_t httpPort = 80;
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
File fsUploadFile; File fsUploadFile;
#endif #endif
char httpUser[32] = ""; 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
#if defined(STM32F4xx) && HASP_USE_WIFI > 0 #if defined(STM32F4xx) && HASP_USE_WIFI > 0
#include <EthernetWebServer_STM32.h> #include <EthernetWebServer_STM32.h>
// #include <WiFi.h> // #include <WiFi.h>
EthernetWebServer webServer(80); EthernetWebServer webServer(80);
#endif #endif
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
ESP8266WebServer webServer(80); ESP8266WebServer webServer(80);
#endif #endif
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#include <WebServer.h> #include <WebServer.h>
WebServer webServer(80); WebServer webServer(80);
#endif // ESP32 #endif // ESP32
HTTPUpload * upload; HTTPUpload * upload;
@ -103,11 +103,11 @@ String espFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.ino.d1_mi
// Default link to compiled Nextion firmware images // Default link to compiled Nextion firmware images
String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft"; String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft";
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
extern char mqttNodeName[16]; extern char mqttNodeName[16];
#else #else
char mqttNodeName[3] = "na"; char mqttNodeName[3] = "na";
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleHaspConfig(); void webHandleHaspConfig();
@ -127,13 +127,13 @@ bool httpIsAuthenticated(const __FlashStringHelper * fstr_page)
} }
} }
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
Log.notice(TAG_HTTP, F("Sending %S page to client connected from: %s"), fstr_page, Log.notice(TAG_HTTP, F("Sending %S page to client connected from: %s"), fstr_page,
webServer.client().remoteIP().toString().c_str()); webServer.client().remoteIP().toString().c_str());
#else #else
// Log.trace(TAG_HTTP,F("Sending %s page to client connected from: %s"), page, // Log.trace(TAG_HTTP,F("Sending %s page to client connected from: %s"), page,
// String(webServer.client().remoteIP()).c_str()); // String(webServer.client().remoteIP()).c_str());
#endif #endif
return true; return true;
} }
@ -159,15 +159,15 @@ void webSendFooter()
char buffer[16]; char buffer[16];
snprintf_P(buffer, sizeof(buffer), PSTR("%u.%u.%u"), HASP_VERSION_MAJOR, HASP_VERSION_MINOR, HASP_VERSION_REVISION); snprintf_P(buffer, sizeof(buffer), PSTR("%u.%u.%u"), HASP_VERSION_MAJOR, HASP_VERSION_MINOR, HASP_VERSION_REVISION);
#if defined(STM32F4xx) #if defined(STM32F4xx)
webServer.sendContent(HTTP_END); webServer.sendContent(HTTP_END);
webServer.sendContent(buffer); webServer.sendContent(buffer);
webServer.sendContent(HTTP_FOOTER); webServer.sendContent(HTTP_FOOTER);
#else #else
webServer.sendContent_P(HTTP_END); webServer.sendContent_P(HTTP_END);
webServer.sendContent(buffer); webServer.sendContent(buffer);
webServer.sendContent_P(HTTP_FOOTER); webServer.sendContent_P(HTTP_FOOTER);
#endif #endif
} }
void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false) void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false)
@ -194,29 +194,29 @@ void webSendPage(char * nodename, uint32_t httpdatalength, bool gohome = false)
} }
webServer.setContentLength(contentLength + httpdatalength); webServer.setContentLength(contentLength + httpdatalength);
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122 webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122
#else #else
webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122 webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122
#endif #endif
snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename); snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename);
webServer.sendContent(buffer); // 17-2+len webServer.sendContent(buffer); // 17-2+len
} }
#if defined(STM32F4xx) #if defined(STM32F4xx)
webServer.sendContent(HTTP_SCRIPT); // 131 webServer.sendContent(HTTP_SCRIPT); // 131
webServer.sendContent(HTTP_STYLE); // 487 webServer.sendContent(HTTP_STYLE); // 487
webServer.sendContent(HASP_STYLE); // 145 webServer.sendContent(HASP_STYLE); // 145
if(gohome) webServer.sendContent(HTTP_META_GO_BACK); // 47 if(gohome) webServer.sendContent(HTTP_META_GO_BACK); // 47
webServer.sendContent(HTTP_HEADER_END); // 80 webServer.sendContent(HTTP_HEADER_END); // 80
#else #else
webServer.sendContent_P(HTTP_SCRIPT); // 131 webServer.sendContent_P(HTTP_SCRIPT); // 131
webServer.sendContent_P(HTTP_STYLE); // 487 webServer.sendContent_P(HTTP_STYLE); // 487
webServer.sendContent_P(HASP_STYLE); // 145 webServer.sendContent_P(HASP_STYLE); // 145
if(gohome) webServer.sendContent_P(HTTP_META_GO_BACK); // 47 if(gohome) webServer.sendContent_P(HTTP_META_GO_BACK); // 47
webServer.sendContent_P(HTTP_HEADER_END); // 80 webServer.sendContent_P(HTTP_HEADER_END); // 80
#endif #endif
} }
void webHandleRoot() void webHandleRoot()
@ -239,12 +239,12 @@ void webHandleRoot()
httpMessage += httpMessage +=
F("<p><form method='get' action='firmware'><button type='submit'>Firmware Upgrade</button></form></p>"); F("<p><form method='get' action='firmware'><button type='submit'>Firmware Upgrade</button></form></p>");
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
if(HASP_FS.exists(F("/edit.htm.gz"))) { if(HASP_FS.exists(F("/edit.htm.gz"))) {
httpMessage += F("<p><form method='get' action='edit.htm.gz?path=/'><button type='submit'>File " httpMessage += F("<p><form method='get' action='edit.htm.gz?path=/'><button type='submit'>File "
"Browser</button></form></p>"); "Browser</button></form></p>");
} }
#endif #endif
httpMessage += httpMessage +=
F("<p><form method='get' action='reboot'><button class='red' type='submit'>Restart</button></form></p>"); F("<p><form method='get' action='reboot'><button class='red' type='submit'>Restart</button></form></p>");
@ -366,15 +366,15 @@ void webHandleAbout()
F("<p><h3>ArduinoLog</h3>Copyright&copy; 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, " F("<p><h3>ArduinoLog</h3>Copyright&copy; 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, "
"dhylands, Josha blemasle, mfalkvidd"); "dhylands, Josha blemasle, mfalkvidd");
httpMessage += FPSTR(MIT_LICENSE); httpMessage += FPSTR(MIT_LICENSE);
#if HASP_USE_SYSLOG > 0 #if HASP_USE_SYSLOG > 0
// Replaced with WiFiUDP client // Replaced with WiFiUDP client
// httpMessage += F("<p><h3>Syslog</h3>Copyright&copy; 2016 Martin Sloup"); // httpMessage += F("<p><h3>Syslog</h3>Copyright&copy; 2016 Martin Sloup");
// httpMessage += FPSTR(MIT_LICENSE); // httpMessage += FPSTR(MIT_LICENSE);
#endif #endif
#if HASP_USE_QRCODE > 0 #if HASP_USE_QRCODE > 0
httpMessage += F("<p><h3>QR Code generator</h3>Copyright&copy; Project Nayuki"); httpMessage += F("<p><h3>QR Code generator</h3>Copyright&copy; Project Nayuki");
httpMessage += FPSTR(MIT_LICENSE); httpMessage += FPSTR(MIT_LICENSE);
#endif #endif
httpMessage += F("<p><h3>AceButton</h3>Copyright&copy; 2018 Brian T. Park"); httpMessage += F("<p><h3>AceButton</h3>Copyright&copy; 2018 Brian T. Park");
httpMessage += FPSTR(MIT_LICENSE); httpMessage += FPSTR(MIT_LICENSE);
@ -441,14 +441,14 @@ void webHandleInfo()
httpMessage += F("<br/><b>Memory Fragmentation: </b>"); httpMessage += F("<br/><b>Memory Fragmentation: </b>");
httpMessage += String(halGetHeapFragmentation()); httpMessage += String(halGetHeapFragmentation());
#if ARDUINO_ARCH_ESP32 #if ARDUINO_ARCH_ESP32
if(psramFound()) { if(psramFound()) {
httpMessage += F("<br/><b>Free PSRam: </b>"); httpMessage += F("<br/><b>Free PSRam: </b>");
httpMessage += halFormatBytes(ESP.getFreePsram()); httpMessage += halFormatBytes(ESP.getFreePsram());
httpMessage += F("<br/><b>PSRam Size: </b>"); httpMessage += F("<br/><b>PSRam Size: </b>");
httpMessage += halFormatBytes(ESP.getPsramSize()); httpMessage += halFormatBytes(ESP.getPsramSize());
} }
#endif #endif
/* LVGL Stats */ /* LVGL Stats */
lv_mem_monitor_t mem_mon; lv_mem_monitor_t mem_mon;
@ -467,7 +467,7 @@ void webHandleInfo()
httpMessage += String(haspGetPage()); httpMessage += String(haspGetPage());
/* Wifi Stats */ /* Wifi Stats */
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
httpMessage += F("</p/><p><b>SSID: </b>"); httpMessage += F("</p/><p><b>SSID: </b>");
httpMessage += String(WiFi.SSID()); httpMessage += String(WiFi.SSID());
httpMessage += F("</br><b>Signal Strength: </b>"); httpMessage += F("</br><b>Signal Strength: </b>");
@ -487,7 +487,7 @@ void webHandleInfo()
} else { } else {
httpMessage += F("Very Bad)"); httpMessage += F("Very Bad)");
} }
#if defined(STM32F4xx) #if defined(STM32F4xx)
byte mac[6]; byte mac[6];
WiFi.macAddress(mac); WiFi.macAddress(mac);
char macAddress[16]; char macAddress[16];
@ -499,7 +499,7 @@ void webHandleInfo()
httpMessage += String(WiFi.gatewayIP()); httpMessage += String(WiFi.gatewayIP());
httpMessage += F("</br><b>MAC Address: </b>"); httpMessage += F("</br><b>MAC Address: </b>");
httpMessage += String(macAddress); httpMessage += String(macAddress);
#else #else
httpMessage += F("</br><b>IP Address: </b>"); httpMessage += F("</br><b>IP Address: </b>");
httpMessage += String(WiFi.localIP().toString()); httpMessage += String(WiFi.localIP().toString());
httpMessage += F("</br><b>Gateway: </b>"); httpMessage += F("</br><b>Gateway: </b>");
@ -508,10 +508,10 @@ void webHandleInfo()
httpMessage += String(WiFi.dnsIP().toString()); httpMessage += String(WiFi.dnsIP().toString());
httpMessage += F("</br><b>MAC Address: </b>"); httpMessage += F("</br><b>MAC Address: </b>");
httpMessage += String(WiFi.macAddress()); httpMessage += String(WiFi.macAddress());
#endif #endif
#endif #endif
#if HASP_USE_ETHERNET > 0 #if HASP_USE_ETHERNET > 0
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
httpMessage += F("</p/><p><b>Ethernet: </b>"); httpMessage += F("</p/><p><b>Ethernet: </b>");
httpMessage += String(ETH.linkSpeed()); httpMessage += String(ETH.linkSpeed());
httpMessage += F(" Mbps"); httpMessage += F(" Mbps");
@ -526,10 +526,10 @@ void webHandleInfo()
httpMessage += String(ETH.dnsIP().toString()); httpMessage += String(ETH.dnsIP().toString());
httpMessage += F("</br><b>MAC Address: </b>"); httpMessage += F("</br><b>MAC Address: </b>");
httpMessage += String(ETH.macAddress()); httpMessage += String(ETH.macAddress());
#endif #endif
#endif #endif
/* Mqtt Stats */ /* Mqtt Stats */
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
httpMessage += F("</p/><p><b>MQTT Status: </b>"); httpMessage += F("</p/><p><b>MQTT Status: </b>");
if(mqttIsConnected()) { // Check MQTT connection if(mqttIsConnected()) { // Check MQTT connection
httpMessage += F("Connected"); httpMessage += F("Connected");
@ -547,7 +547,7 @@ void webHandleInfo()
httpMessage += mqttClientId; httpMessage += mqttClientId;
} }
#endif // MQTT #endif // MQTT
/* ESP Stats */ /* ESP Stats */
httpMessage += F("</p/><p><b>MCU Model: </b>"); httpMessage += F("</p/><p><b>MCU Model: </b>");
@ -555,14 +555,14 @@ void webHandleInfo()
httpMessage += F("<br/><b>CPU Frequency: </b>"); httpMessage += F("<br/><b>CPU Frequency: </b>");
httpMessage += String(halGetCpuFreqMHz()); httpMessage += String(halGetCpuFreqMHz());
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
httpMessage += F("MHz<br/><b>Flash Chip Size: </b>"); httpMessage += F("MHz<br/><b>Flash Chip Size: </b>");
httpMessage += halFormatBytes(ESP.getFlashChipSize()); httpMessage += halFormatBytes(ESP.getFlashChipSize());
httpMessage += F("</br><b>Program Size: </b>"); httpMessage += F("</br><b>Program Size: </b>");
httpMessage += halFormatBytes(ESP.getSketchSize()); httpMessage += halFormatBytes(ESP.getSketchSize());
httpMessage += F("<br/><b>Free Program Space: </b>"); httpMessage += F("<br/><b>Free Program Space: </b>");
httpMessage += halFormatBytes(ESP.getFreeSketchSpace()); httpMessage += halFormatBytes(ESP.getFreeSketchSpace());
#endif #endif
//#if defined(ARDUINO_ARCH_ESP32) //#if defined(ARDUINO_ARCH_ESP32)
// httpMessage += F("<br/><b>ESP SDK version: </b>"); // httpMessage += F("<br/><b>ESP SDK version: </b>");
@ -651,7 +651,7 @@ void webUploadProgress()
haspProgressVal(t); haspProgressVal(t);
} }
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
void webUpdatePrintError() void webUpdatePrintError()
{ {
String output((char *)0); 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) bool handleFileRead(String path)
{ {
if(!httpIsAuthenticated(F("fileread"))) return false; if(!httpIsAuthenticated(F("fileread"))) return false;
@ -848,7 +848,7 @@ void handleFileList()
Log.notice(TAG_HTTP, F("handleFileList: %s"), path.c_str()); Log.notice(TAG_HTTP, F("handleFileList: %s"), path.c_str());
path.clear(); path.clear();
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
File root = HASP_FS.open("/", FILE_READ); File root = HASP_FS.open("/", FILE_READ);
File file = root.openNextFile(); File file = root.openNextFile();
String output = "["; String output = "[";
@ -873,7 +873,7 @@ void handleFileList()
} }
output += "]"; output += "]";
webServer.send(200, PSTR("text/json"), output); webServer.send(200, PSTR("text/json"), output);
#elif defined(ARDUINO_ARCH_ESP8266) #elif defined(ARDUINO_ARCH_ESP8266)
Dir dir = HASP_FS.openDir(path); Dir dir = HASP_FS.openDir(path);
String output = "["; String output = "[";
while(dir.next()) { while(dir.next()) {
@ -895,9 +895,9 @@ void handleFileList()
} }
output += "]"; output += "]";
webServer.send(200, PSTR("text/json"), output); webServer.send(200, PSTR("text/json"), output);
#endif #endif
} }
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleConfig() void webHandleConfig()
@ -914,10 +914,10 @@ void webHandleConfig()
if(save == String(PSTR("hasp"))) { if(save == String(PSTR("hasp"))) {
haspSetConfig(settings.as<JsonObject>()); haspSetConfig(settings.as<JsonObject>());
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
} else if(save == String(PSTR("mqtt"))) { } else if(save == String(PSTR("mqtt"))) {
mqttSetConfig(settings.as<JsonObject>()); mqttSetConfig(settings.as<JsonObject>());
#endif #endif
} else if(save == String(PSTR("gui"))) { } else if(save == String(PSTR("gui"))) {
settings[FPSTR(F_GUI_POINTER)] = webServer.hasArg(PSTR("pointer")); settings[FPSTR(F_GUI_POINTER)] = webServer.hasArg(PSTR("pointer"));
@ -932,20 +932,20 @@ void webHandleConfig()
// Password might have changed // Password might have changed
if(!httpIsAuthenticated(F("config"))) return; if(!httpIsAuthenticated(F("config"))) return;
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
} else if(save == String(PSTR("wifi"))) { } else if(save == String(PSTR("wifi"))) {
wifiSetConfig(settings.as<JsonObject>()); wifiSetConfig(settings.as<JsonObject>());
#endif #endif
} }
} }
} }
// Reboot after saving wifi config in AP mode // Reboot after saving wifi config in AP mode
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) #if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
if(WiFi.getMode() != WIFI_STA) { if(WiFi.getMode() != WIFI_STA) {
httpHandleReboot(); httpHandleReboot();
} }
#endif #endif
{ {
String httpMessage((char *)0); String httpMessage((char *)0);
@ -954,15 +954,15 @@ void webHandleConfig()
httpMessage += httpGetNodename(); httpMessage += httpGetNodename();
httpMessage += F("</h1><hr>"); httpMessage += F("</h1><hr>");
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
httpMessage += httpMessage +=
F("<p><form method='get' action='/config/wifi'><button type='submit'>Wifi Settings</button></form></p>"); F("<p><form method='get' action='/config/wifi'><button type='submit'>Wifi Settings</button></form></p>");
#endif #endif
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
httpMessage += httpMessage +=
F("<p><form method='get' action='/config/mqtt'><button type='submit'>MQTT Settings</button></form></p>"); F("<p><form method='get' action='/config/mqtt'><button type='submit'>MQTT Settings</button></form></p>");
#endif #endif
httpMessage += httpMessage +=
F("<p><form method='get' action='/config/http'><button type='submit'>HTTP Settings</button></form></p>"); F("<p><form method='get' action='/config/http'><button type='submit'>HTTP Settings</button></form></p>");
@ -973,10 +973,10 @@ void webHandleConfig()
httpMessage += httpMessage +=
F("<p><form method='get' action='/config/hasp'><button type='submit'>HASP Settings</button></form></p>"); F("<p><form method='get' action='/config/hasp'><button type='submit'>HASP Settings</button></form></p>");
#if HASP_USE_GPIO > 0 #if HASP_USE_GPIO > 0
httpMessage += httpMessage +=
F("<p><form method='get' action='/config/gpio'><button type='submit'>GPIO Settings</button></form></p>"); F("<p><form method='get' action='/config/gpio'><button type='submit'>GPIO Settings</button></form></p>");
#endif #endif
httpMessage += httpMessage +=
F("<p><form method='get' action='/config/debug'><button type='submit'>Debug Settings</button></form></p>"); F("<p><form method='get' action='/config/debug'><button type='submit'>Debug Settings</button></form></p>");
@ -994,8 +994,8 @@ void webHandleConfig()
webSendFooter(); webSendFooter();
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
void webHandleMqttConfig() void webHandleMqttConfig()
{ // http://plate01/config/mqtt { // http://plate01/config/mqtt
if(!httpIsAuthenticated(F("config/mqtt"))) return; if(!httpIsAuthenticated(F("config/mqtt"))) return;
@ -1042,7 +1042,7 @@ void webHandleMqttConfig()
// httpMessage.clear(); // httpMessage.clear();
webSendFooter(); webSendFooter();
} }
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleGuiConfig() void webHandleGuiConfig()
@ -1090,7 +1090,7 @@ void webHandleGuiConfig()
int8_t bcklpin = settings[FPSTR(F_GUI_BACKLIGHTPIN)].as<int8_t>(); int8_t bcklpin = settings[FPSTR(F_GUI_BACKLIGHTPIN)].as<int8_t>();
httpMessage += F("<p><b>Backlight Control</b> <select id='bcklpin' name='bcklpin'>"); httpMessage += F("<p><b>Backlight Control</b> <select id='bcklpin' name='bcklpin'>");
httpMessage += getOption(-1, F("None"), bcklpin == -1); httpMessage += getOption(-1, F("None"), bcklpin == -1);
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
httpMessage += getOption(5, F("GPIO 5"), bcklpin == 5); // D8 on ESP32 for D1 mini 32 httpMessage += getOption(5, F("GPIO 5"), bcklpin == 5); // D8 on ESP32 for D1 mini 32
httpMessage += getOption(16, F("GPIO 16"), bcklpin == 16); // D4 on ESP32 for D1 mini 32 httpMessage += getOption(16, F("GPIO 16"), bcklpin == 16); // D4 on ESP32 for D1 mini 32
httpMessage += getOption(17, F("GPIO 17"), bcklpin == 17); // D3 on ESP32 for D1 mini 32 httpMessage += getOption(17, F("GPIO 17"), bcklpin == 17); // D3 on ESP32 for D1 mini 32
@ -1100,12 +1100,12 @@ void webHandleGuiConfig()
httpMessage += getOption(22, F("GPIO 22"), bcklpin == 22); // D2 on ESP32 for D1 mini 32 httpMessage += getOption(22, F("GPIO 22"), bcklpin == 22); // D2 on ESP32 for D1 mini 32
httpMessage += getOption(23, F("GPIO 23"), bcklpin == 23); // D7 on ESP32 for D1 mini 32 httpMessage += getOption(23, F("GPIO 23"), bcklpin == 23); // D7 on ESP32 for D1 mini 32
httpMessage += getOption(32, F("GPIO 32"), bcklpin == 32); // TFT_LED on the Lolin D32 Pro httpMessage += getOption(32, F("GPIO 32"), bcklpin == 32); // TFT_LED on the Lolin D32 Pro
#else #else
httpMessage += getOption(5, F("D1 - GPIO 5"), bcklpin == 5); httpMessage += getOption(5, F("D1 - GPIO 5"), bcklpin == 5);
httpMessage += getOption(4, F("D2 - GPIO 4"), bcklpin == 4); httpMessage += getOption(4, F("D2 - GPIO 4"), bcklpin == 4);
httpMessage += getOption(0, F("D3 - GPIO 0"), bcklpin == 0); httpMessage += getOption(0, F("D3 - GPIO 0"), bcklpin == 0);
httpMessage += getOption(2, F("D4 - GPIO 2"), bcklpin == 2); httpMessage += getOption(2, F("D4 - GPIO 2"), bcklpin == 2);
#endif #endif
httpMessage += F("</select></p>"); httpMessage += F("</select></p>");
httpMessage += F("<p><button type='submit' name='save' value='gui'>Save Settings</button></p></form>"); httpMessage += F("<p><button type='submit' name='save' value='gui'>Save Settings</button></p></form>");
@ -1124,8 +1124,8 @@ void webHandleGuiConfig()
if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); 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() void webHandleWifiConfig()
{ // http://plate01/config/wifi { // http://plate01/config/wifi
if(!httpIsAuthenticated(F("config/wifi"))) return; if(!httpIsAuthenticated(F("config/wifi"))) return;
@ -1150,26 +1150,26 @@ void webHandleWifiConfig()
} }
httpMessage += F("'><p><button type='submit' name='save' value='wifi'>Save Settings</button></p></form>"); httpMessage += F("'><p><button type='submit' name='save' value='wifi'>Save Settings</button></p></form>");
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) #if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
if(WiFi.getMode() == WIFI_STA) { if(WiFi.getMode() == WIFI_STA) {
httpMessage += httpMessage +=
PSTR("<p><form method='get' action='/config'><button type='submit'>Configuration</button></form></p>"); PSTR("<p><form method='get' action='/config'><button type='submit'>Configuration</button></form></p>");
} }
#endif #endif
webSendPage(httpGetNodename(), httpMessage.length(), false); webSendPage(httpGetNodename(), httpMessage.length(), false);
webServer.sendContent(httpMessage); webServer.sendContent(httpMessage);
#if defined(STM32F4xx) #if defined(STM32F4xx)
httpMessage = ""; httpMessage = "";
#else #else
httpMessage.clear(); httpMessage.clear();
#endif #endif
webSendFooter(); webSendFooter();
} }
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if HASP_USE_HTTP > 0 #if HASP_USE_HTTP > 0
void webHandleHttpConfig() void webHandleHttpConfig()
{ // http://plate01/config/http { // http://plate01/config/http
if(!httpIsAuthenticated(F("config/http"))) return; if(!httpIsAuthenticated(F("config/http"))) return;
@ -1204,10 +1204,10 @@ void webHandleHttpConfig()
// httpMessage.clear(); // httpMessage.clear();
webSendFooter(); webSendFooter();
} }
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) #if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0)
void webHandleGpioConfig() void webHandleGpioConfig()
{ // http://plate01/config/gpio { // http://plate01/config/gpio
if(!httpIsAuthenticated(F("config/gpio"))) return; if(!httpIsAuthenticated(F("config/gpio"))) return;
@ -1224,6 +1224,11 @@ void webHandleGpioConfig()
uint8_t pinfunc = webServer.arg(F("func")).toInt(); uint8_t pinfunc = webServer.arg(F("func")).toInt();
gpioSavePinConfig(id, pin, type, group, pinfunc); 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); String httpMessage((char *)0);
@ -1284,8 +1289,10 @@ void webHandleGpioConfig()
httpMessage += F("</td><td><a href='/config/gpio/options?id="); httpMessage += F("</td><td><a href='/config/gpio/options?id=");
httpMessage += id; httpMessage += id;
httpMessage += ("'>Edit</a> <a href='/config/gpio?save=&id="); httpMessage += ("'>Edit</a> <a href='/config/gpio?del=&id=");
httpMessage += id; httpMessage += id;
httpMessage += ("&pin=");
httpMessage += conf.pin;
httpMessage += ("'>Delete</a></td><tr>"); httpMessage += ("'>Delete</a></td><tr>");
configCount++; configCount++;
} }
@ -1400,7 +1407,7 @@ void webHandleGpioOptions()
if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check
} }
#endif // HASP_USE_GPIO #endif // HASP_USE_GPIO
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void webHandleDebugConfig() void webHandleDebugConfig()
@ -1433,7 +1440,7 @@ void webHandleDebugConfig()
httpMessage += settings[FPSTR(F_DEBUG_TELEPERIOD)].as<String>(); httpMessage += settings[FPSTR(F_DEBUG_TELEPERIOD)].as<String>();
httpMessage += F("'></p>"); httpMessage += F("'></p>");
#if HASP_USE_SYSLOG > 0 #if HASP_USE_SYSLOG > 0
httpMessage += F("<b>Syslog Hostame</b> <i><small>(optional)</small></i><input id='host' " httpMessage += F("<b>Syslog Hostame</b> <i><small>(optional)</small></i><input id='host' "
"name='host' maxlength=31 placeholder='logserver' value='"); "name='host' maxlength=31 placeholder='logserver' value='");
httpMessage += settings[FPSTR(F_CONFIG_HOST)].as<String>(); httpMessage += settings[FPSTR(F_CONFIG_HOST)].as<String>();
@ -1452,7 +1459,7 @@ void webHandleDebugConfig()
httpMessage += F(">IETF (RFC 5424) &nbsp; <input id='proto' name='proto' type='radio' value='1'"); httpMessage += F(">IETF (RFC 5424) &nbsp; <input id='proto' name='proto' type='radio' value='1'");
if(settings[FPSTR(F_CONFIG_PROTOCOL)].as<uint8_t>() == 1) httpMessage += F(" checked"); if(settings[FPSTR(F_CONFIG_PROTOCOL)].as<uint8_t>() == 1) httpMessage += F(" checked");
httpMessage += F(">BSD (RFC 3164)"); httpMessage += F(">BSD (RFC 3164)");
#endif #endif
httpMessage += F("</p><p><button type='submit' name='save' value='debug'>Save Settings</button></p></form>"); httpMessage += F("</p><p><button type='submit' name='save' value='debug'>Save Settings</button></p></form>");
@ -1490,35 +1497,35 @@ void webHandleHaspConfig()
uint8_t themeid = settings[FPSTR(F_CONFIG_THEME)].as<uint8_t>(); uint8_t themeid = settings[FPSTR(F_CONFIG_THEME)].as<uint8_t>();
// httpMessage += getOption(0, F("Built-in"), themeid == 0); // httpMessage += getOption(0, F("Built-in"), themeid == 0);
#if LV_USE_THEME_HASP == 1 #if LV_USE_THEME_HASP == 1
httpMessage += getOption(2, F("Hasp Dark"), themeid == 2); httpMessage += getOption(2, F("Hasp Dark"), themeid == 2);
httpMessage += getOption(1, F("Hasp Light"), themeid == 1); httpMessage += getOption(1, F("Hasp Light"), themeid == 1);
#endif #endif
#if LV_USE_THEME_EMPTY == 1 #if LV_USE_THEME_EMPTY == 1
httpMessage += getOption(0, F("Empty"), themeid == 0); httpMessage += getOption(0, F("Empty"), themeid == 0);
#endif #endif
#if LV_USE_THEME_ALIEN == 1 #if LV_USE_THEME_ALIEN == 1
httpMessage += getOption(1, F("Alien"), themeid == 1); httpMessage += getOption(1, F("Alien"), themeid == 1);
#endif #endif
#if LV_USE_THEME_NIGHT == 1 #if LV_USE_THEME_NIGHT == 1
httpMessage += getOption(2, F("Night"), themeid == 2); httpMessage += getOption(2, F("Night"), themeid == 2);
#endif #endif
#if LV_USE_THEME_MONO == 1 #if LV_USE_THEME_MONO == 1
httpMessage += getOption(3, F("Mono"), themeid == 3); httpMessage += getOption(3, F("Mono"), themeid == 3);
#endif #endif
#if LV_USE_THEME_MATERIAL == 1 #if LV_USE_THEME_MATERIAL == 1
httpMessage += getOption(5, F("Material Dark"), themeid == 5); httpMessage += getOption(5, F("Material Dark"), themeid == 5);
httpMessage += getOption(4, F("Material Light"), themeid == 4); httpMessage += getOption(4, F("Material Light"), themeid == 4);
#endif #endif
#if LV_USE_THEME_ZEN == 1 #if LV_USE_THEME_ZEN == 1
// httpMessage += getOption(5, F("Zen"), themeid == 5); // httpMessage += getOption(5, F("Zen"), themeid == 5);
#endif #endif
#if LV_USE_THEME_NEMO == 1 #if LV_USE_THEME_NEMO == 1
httpMessage += getOption(6, F("Nemo"), themeid == 6); httpMessage += getOption(6, F("Nemo"), themeid == 6);
#endif #endif
#if LV_USE_THEME_TEMPLATE == 1 #if LV_USE_THEME_TEMPLATE == 1
httpMessage += getOption(7, F("Template"), themeid == 7); httpMessage += getOption(7, F("Template"), themeid == 7);
#endif #endif
httpMessage += F("</select></br>"); httpMessage += F("</select></br>");
httpMessage += httpMessage +=
F("<b>Hue</b><div style='width:100%;background-image:linear-gradient(to " F("<b>Hue</b><div style='width:100%;background-image:linear-gradient(to "
@ -1528,7 +1535,7 @@ void webHandleHaspConfig()
httpMessage += F("'></div></p>"); httpMessage += F("'></div></p>");
httpMessage += F("<p><b>Default Font</b><select id='font' name='font'><option value=''>None</option>"); httpMessage += F("<p><b>Default Font</b><select id='font' name='font'><option value=''>None</option>");
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
File root = HASP_FS.open("/"); File root = HASP_FS.open("/");
File file = root.openNextFile(); File file = root.openNextFile();
@ -1539,7 +1546,7 @@ void webHandleHaspConfig()
getOption(file.name(), file.name(), filename == settings[FPSTR(F_CONFIG_ZIFONT)].as<String>()); getOption(file.name(), file.name(), filename == settings[FPSTR(F_CONFIG_ZIFONT)].as<String>());
file = root.openNextFile(); file = root.openNextFile();
} }
#elif defined(ARDUINO_ARCH_ESP8266) #elif defined(ARDUINO_ARCH_ESP8266)
Dir dir = HASP_FS.openDir("/"); Dir dir = HASP_FS.openDir("/");
while(dir.next()) { while(dir.next()) {
File file = dir.openFile("r"); File file = dir.openFile("r");
@ -1549,7 +1556,7 @@ void webHandleHaspConfig()
getOption(file.name(), file.name(), filename == settings[FPSTR(F_CONFIG_ZIFONT)].as<String>()); getOption(file.name(), file.name(), filename == settings[FPSTR(F_CONFIG_ZIFONT)].as<String>());
file.close(); file.close();
} }
#endif #endif
httpMessage += F("</select></p>"); httpMessage += F("</select></p>");
httpMessage += F("<p><b>Startup Layout</b> <i><small>(optional)</small></i><input id='pages' " httpMessage += F("<p><b>Startup Layout</b> <i><small>(optional)</small></i><input id='pages' "
@ -1580,16 +1587,16 @@ void webHandleHaspConfig()
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void httpHandleNotFound() void httpHandleNotFound()
{ // webServer 404 { // webServer 404
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
if(handleFileRead(webServer.uri())) return; 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"), Log.notice(TAG_HTTP, F("Sending 404 to client connected from: %s"),
webServer.client().remoteIP().toString().c_str()); 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()); // Log.notice(TAG_HTTP,F("Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str());
#endif #endif
String httpMessage((char *)0); String httpMessage((char *)0);
httpMessage.reserve(HTTP_PAGE_SIZE); httpMessage.reserve(HTTP_PAGE_SIZE);
@ -1723,24 +1730,24 @@ void httpStart()
{ {
webServer.begin(); webServer.begin();
webServerStarted = true; webServerStarted = true;
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
#if defined(STM32F4xx) #if defined(STM32F4xx)
IPAddress ip; IPAddress ip;
ip = WiFi.localIP(); ip = WiFi.localIP();
Log.trace(TAG_HTTP, F("Server started @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); 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"), Log.trace(TAG_HTTP, F("Server started @ http://%s"),
(WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str())); (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str()));
#endif #endif
#else #else
IPAddress ip; IPAddress ip;
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
ip = ETH.localIP(); ip = ETH.localIP();
#else #else
ip = Ethernet.localIP(); 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]); Log.trace(TAG_HTTP, F("Server started @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
#endif #endif
} }
void httpStop() void httpStop()
@ -1755,14 +1762,14 @@ void httpSetup()
{ {
// httpSetConfig(settings); // httpSetConfig(settings);
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
#if !defined(STM32F4xx) #if !defined(STM32F4xx)
if(WiFi.getMode() != WIFI_STA) { if(WiFi.getMode() != WIFI_STA) {
Log.notice(TAG_HTTP, F("Wifi access point")); Log.notice(TAG_HTTP, F("Wifi access point"));
webServer.on(F("/"), webHandleWifiConfig); webServer.on(F("/"), webHandleWifiConfig);
} else { } else {
#endif #endif
#endif #endif
webServer.on(F("/page/"), []() { webServer.on(F("/page/"), []() {
String pageid = webServer.arg(F("page")); String pageid = webServer.arg(F("page"));
@ -1770,7 +1777,7 @@ void httpSetup()
haspSetPage(pageid.toInt()); 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); webServer.on(F("/list"), HTTP_GET, handleFileList);
// load editor // load editor
webServer.on(F("/edit"), HTTP_GET, []() { webServer.on(F("/edit"), HTTP_GET, []() {
@ -1791,7 +1798,7 @@ void httpSetup()
Log.verbose(TAG_HTTP, F("Headers: %d"), webServer.headers()); Log.verbose(TAG_HTTP, F("Headers: %d"), webServer.headers());
}, },
handleFileUpload); 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
/*webServer.on(F("/all"), HTTP_GET, []() { /*webServer.on(F("/all"), HTTP_GET, []() {
@ -1816,21 +1823,21 @@ void httpSetup()
webServer.on(F("/config/http"), webHandleHttpConfig); webServer.on(F("/config/http"), webHandleHttpConfig);
webServer.on(F("/config/gui"), webHandleGuiConfig); webServer.on(F("/config/gui"), webHandleGuiConfig);
webServer.on(F("/config/debug"), webHandleDebugConfig); webServer.on(F("/config/debug"), webHandleDebugConfig);
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
webServer.on(F("/config/mqtt"), webHandleMqttConfig); webServer.on(F("/config/mqtt"), webHandleMqttConfig);
#endif #endif
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
webServer.on(F("/config/wifi"), webHandleWifiConfig); webServer.on(F("/config/wifi"), webHandleWifiConfig);
#endif #endif
#if HASP_USE_GPIO > 0 #if HASP_USE_GPIO > 0
webServer.on(F("/config/gpio"), webHandleGpioConfig); webServer.on(F("/config/gpio"), webHandleGpioConfig);
webServer.on(F("/config/gpio/options"), webHandleGpioOptions); webServer.on(F("/config/gpio/options"), webHandleGpioOptions);
#endif #endif
webServer.on(F("/screenshot"), webHandleScreenshot); webServer.on(F("/screenshot"), webHandleScreenshot);
webServer.on(F("/saveConfig"), webHandleSaveConfig); webServer.on(F("/saveConfig"), webHandleSaveConfig);
webServer.on(F("/resetConfig"), httpHandleResetConfig); webServer.on(F("/resetConfig"), httpHandleResetConfig);
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, F("/update"), HTTP_POST,
[]() { []() {
@ -1839,14 +1846,14 @@ void httpSetup()
}, },
webHandleFirmwareUpdate); webHandleFirmwareUpdate);
webServer.on(F("/espfirmware"), httpHandleEspFirmware); webServer.on(F("/espfirmware"), httpHandleEspFirmware);
#endif #endif
webServer.on(F("/reboot"), httpHandleReboot); webServer.on(F("/reboot"), httpHandleReboot);
webServer.onNotFound(httpHandleNotFound); webServer.onNotFound(httpHandleNotFound);
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
#if !defined(STM32F4xx) #if !defined(STM32F4xx)
} }
#endif #endif
#endif #endif
// Shared pages // Shared pages
webServer.on(F("/about"), webHandleAbout); webServer.on(F("/about"), webHandleAbout);
@ -1870,9 +1877,9 @@ void httpReconnect()
if(webServerStarted) { if(webServerStarted) {
httpStop(); httpStop();
} else } else
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx) #if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA) if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA)
#endif #endif
{ {
httpStart(); httpStart();
} }