From 6e4127398b405a57812d232639473361afeda310 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sun, 20 Oct 2024 15:52:25 +0200 Subject: [PATCH] add wifiSettings page , wip --- Arduino/CanGrow/include/CanGrow_Webserver.h | 1 + Arduino/CanGrow/include/Webserver/Page_root.h | 4 +-- Arduino/CanGrow/include/Webserver/Page_wifi.h | 31 +++++++++++++++++++ .../include/Webserver/Page_wifi_HTML.h | 26 ++++++++++++++++ Arduino/CanGrow/include/Webserver/header.h | 2 +- 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/Arduino/CanGrow/include/CanGrow_Webserver.h b/Arduino/CanGrow/include/CanGrow_Webserver.h index 19f7a47..2d3cec0 100644 --- a/Arduino/CanGrow/include/CanGrow_Webserver.h +++ b/Arduino/CanGrow/include/CanGrow_Webserver.h @@ -75,6 +75,7 @@ void SetupWebserver() { /* url handler definition */ webserver.on("/", HTTP_GET, WebPage_root); webserver.on("/cangrow.css", HTTP_GET, WebFile_cangrow_CSS); + webserver.on("/wifiSettings", HTTP_GET, WebPage_wifi); requestLogger.setOutput(Serial); // this activates the middleware diff --git a/Arduino/CanGrow/include/Webserver/Page_root.h b/Arduino/CanGrow/include/Webserver/Page_root.h index 514c544..045b543 100644 --- a/Arduino/CanGrow/include/Webserver/Page_root.h +++ b/Arduino/CanGrow/include/Webserver/Page_root.h @@ -35,9 +35,7 @@ String Proc_WebPage_root(const String& var) { if(TestHeaderFooter(var)) { return AddHeaderFooter(var); - } - - if(var == "LOL") { + } else if(var == "LOL") { return String("Nice"); } else if(var == "LOL") { return String("Jojoojo :)"); diff --git a/Arduino/CanGrow/include/Webserver/Page_wifi.h b/Arduino/CanGrow/include/Webserver/Page_wifi.h index b94b7cd..682b708 100644 --- a/Arduino/CanGrow/include/Webserver/Page_wifi.h +++ b/Arduino/CanGrow/include/Webserver/Page_wifi.h @@ -28,3 +28,34 @@ */ +#include "Page_wifi_HTML.h" + + + +// https://techtutorialsx.com/2018/07/23/esp32-arduino-http-server-template-processing-with-multiple-placeholders/ +String Proc_WebPage_wifi(const String& var) { + if(TestHeaderFooter(var)) { + return AddHeaderFooter(var); + //SNIP_CURRSETTINGS + } else if(var == "CONFIGWIFI_SSID") { + return String(configWifi.ssid); + } else if(var == "CONFIGWIFI_DHCP") { + return String(configWifi.dhcp); + } else if(var == "CONFIGWIFI_IP") { + return String(WiFi.localIP().toString()); + } else if(var == "CONFIGWIFI_NETMASK") { + return String(WiFi.subnetMask().toString()); + } else if(var == "CONFIGWIFI_GATEWAY") { + return String(WiFi.gatewayIP().toString()); + } else if(var == "CONFIGWIFI_DNS") { + return String(WiFi.dnsIP().toString()); + } else if(var == "WIFI_LIST") { + return String(""); + } else { + return String(); + } +} + +void WebPage_wifi(AsyncWebServerRequest *request) { + request->send_P(200, "text/html", Page_wifi_HTML, Proc_WebPage_wifi); +} diff --git a/Arduino/CanGrow/include/Webserver/Page_wifi_HTML.h b/Arduino/CanGrow/include/Webserver/Page_wifi_HTML.h index 28aaa6b..2923b12 100644 --- a/Arduino/CanGrow/include/Webserver/Page_wifi_HTML.h +++ b/Arduino/CanGrow/include/Webserver/Page_wifi_HTML.h @@ -26,3 +26,29 @@ * THE SOFTWARE. * */ + +const char* Page_wifi_HTML PROGMEM = R"(%HEADER% +

📡 WiFi settings

+%SNIP_CURRSETTINGS% +

Select your wifi network from the SSID list. +
To use DHCP leave IP, Subnet, Gateway and DNS fields blank!

+
+SSID:
+Password:
+IP:
+Subnet mask:
+Gateway:
+DNS:
+ +
+%FOOTER%)"; + +const char* Page_wifi_HTML_curSettings PROGMEM = R"(Current Settings:
WiFi SSID: %CONFIGWIFI_SSID%
+Use DHCP: %CONFIGWIFI_DHCP%
+IP address: %CONFIGWIFI_IP%
+Subnet mask: %CONFIGWIFI_NETMASK%
+Gateway: %CONFIGWIFI_GATEWAY%
+DNS: %CONFIGWIFI_DNS%

)"; diff --git a/Arduino/CanGrow/include/Webserver/header.h b/Arduino/CanGrow/include/Webserver/header.h index fc502ab..2a5260e 100644 --- a/Arduino/CanGrow/include/Webserver/header.h +++ b/Arduino/CanGrow/include/Webserver/header.h @@ -42,7 +42,7 @@ const char* Header_HTML PROGMEM = R"(