saving ssid, password and ip works so far

This commit is contained in:
Marcus 2024-10-21 01:54:27 +02:00
parent c2d6d508a2
commit ae7f6cd3f7
3 changed files with 46 additions and 3 deletions

View file

@ -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;

View file

@ -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);

View file

@ -29,17 +29,27 @@
const char* Page_wifi_HTML PROGMEM = R"(%HEADER%
<h2>&#128225; WiFi settings</h2>
%SAVE_MSG%
%CURRENT_SETTINGS%
<p>Select your wifi network from the SSID list.
<br>Reload the page, if your network is not listed.</p>
<form method='post' action='/wifiSettings/save'>
SSID: <select id='configWifi.ssid' name='configWifi.ssid' required>
<option disabled value='' selected hidden>-Select your network-</option>
%WIFI_LIST%
</select><br>
Password: <input type='password' name='configWifi.password'><br>
IP: <input type='text' name='configWifi.ip'><br>
IP: <input class='inputShort' type='number' min='0' max='255' name='configWifi.ip0'> .
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip1'> .
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip2'> .
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip3'><br>
Subnet mask: <input type='text' name='configWifi.netmask'><br>
Gateway: <input type='text' name='configWifi.gateway'><br>
DNS: <input type='text' name='configWifi.dns'><br>