From ae7f6cd3f72aee899728820489a3f29eb25dab60 Mon Sep 17 00:00:00 2001 From: Marcus Date: Mon, 21 Oct 2024 01:54:27 +0200 Subject: [PATCH] saving ssid, password and ip works so far --- Arduino/CanGrow/include/CanGrow.h | 4 +-- Arduino/CanGrow/include/Webserver/Page_wifi.h | 33 +++++++++++++++++++ .../include/Webserver/Page_wifi_HTML.h | 12 ++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h index edff429..d9de539 100644 --- a/Arduino/CanGrow/include/CanGrow.h +++ b/Arduino/CanGrow/include/CanGrow.h @@ -48,9 +48,9 @@ struct Config_WiFi { char password[64]; byte ip[4] = {192,168,4,20}; byte netmask[4] = {255,255,255,0}; - byte gateway[4] = {192,168,4,254}; + byte gateway[4] = {192,168,4,255}; byte dns[4] = {0,0,0,0}; - bool dhcp; + bool dhcp = true; }; Config_WiFi configWifi; diff --git a/Arduino/CanGrow/include/Webserver/Page_wifi.h b/Arduino/CanGrow/include/Webserver/Page_wifi.h index 334032b..5c356a2 100644 --- a/Arduino/CanGrow/include/Webserver/Page_wifi.h +++ b/Arduino/CanGrow/include/Webserver/Page_wifi.h @@ -93,8 +93,41 @@ String Proc_WebPage_wifi_POST(const String& var) { void WebPage_wifi(AsyncWebServerRequest *request) { if(request->hasParam("configWifi.ssid", true)) { + + const AsyncWebParameter* p_ssid = request->getParam("configWifi.ssid", true); + Serial.printf(":: [Webserver:wifi] POST[%s]: %s\n", p_ssid->name().c_str(), p_ssid->value().c_str()); + strlcpy(configWifi.ssid, p_ssid->value().c_str(), sizeof(configWifi.ssid)); + + const AsyncWebParameter* p_password = request->getParam("configWifi.password", true); + Serial.printf(":: [Webserver:wifi] POST[%s]: %s\n", p_password->name().c_str(), p_password->value().c_str()); + strlcpy(configWifi.password, p_password->value().c_str(), sizeof(configWifi.password)); + + const AsyncWebParameter* p_ip0 = request->getParam("configWifi.ip0", true); + const AsyncWebParameter* p_ip1 = request->getParam("configWifi.ip1", true); + const AsyncWebParameter* p_ip2 = request->getParam("configWifi.ip2", true); + const AsyncWebParameter* p_ip3 = request->getParam("configWifi.ip3", true); + Serial.printf(":: [Webserver:wifi] POST[ip0-3]: %s . %s . %s . %s\n", p_ip0->value().c_str(), p_ip1->value().c_str(), p_ip2->value().c_str(), p_ip3->value().c_str()); + configWifi.ip[0] = p_ip0->value().toInt(); + configWifi.ip[1] = p_ip1->value().toInt(); + configWifi.ip[2] = p_ip2->value().toInt(); + configWifi.ip[3] = p_ip3->value().toInt(); + + /* const AsyncWebParameter* p = request->getParam("configWifi.ssid", true); Serial.printf(":: [Webserver:wifi] POST[%s]: %s\n", p->name().c_str(), p->value().c_str()); + strlcpy(configWifi.ssid, p->value().c_str(), sizeof(configWifi.ssid)); + + const AsyncWebParameter* p = request->getParam("configWifi.ssid", true); + Serial.printf(":: [Webserver:wifi] POST[%s]: %s\n", p->name().c_str(), p->value().c_str()); + strlcpy(configWifi.ssid, p->value().c_str(), sizeof(configWifi.ssid)); + + const AsyncWebParameter* p = request->getParam("configWifi.ssid", true); + Serial.printf(":: [Webserver:wifi] POST[%s]: %s\n", p->name().c_str(), p->value().c_str()); + strlcpy(configWifi.ssid, p->value().c_str(), sizeof(configWifi.ssid)); + */ + SaveConfig(true); + + request->send_P(200, "text/html", Page_wifi_HTML, Proc_WebPage_wifi_POST); } else { 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 7430627..42dabbf 100644 --- a/Arduino/CanGrow/include/Webserver/Page_wifi_HTML.h +++ b/Arduino/CanGrow/include/Webserver/Page_wifi_HTML.h @@ -29,17 +29,27 @@ const char* Page_wifi_HTML PROGMEM = R"(%HEADER%

📡 WiFi settings

+ %SAVE_MSG% %CURRENT_SETTINGS% +

Select your wifi network from the SSID list.
Reload the page, if your network is not listed.

SSID:
+ Password:
-IP:
+ +IP: . + . + . +
+ Subnet mask:
Gateway:
DNS: