configuring and saving wifi settings works now, yay - milestone!
This commit is contained in:
parent
ae7f6cd3f7
commit
825f2e8e19
6 changed files with 141 additions and 44 deletions
|
@ -50,7 +50,7 @@ struct Config_WiFi {
|
||||||
byte netmask[4] = {255,255,255,0};
|
byte netmask[4] = {255,255,255,0};
|
||||||
byte gateway[4] = {192,168,4,255};
|
byte gateway[4] = {192,168,4,255};
|
||||||
byte dns[4] = {0,0,0,0};
|
byte dns[4] = {0,0,0,0};
|
||||||
bool dhcp = true;
|
bool dhcp;
|
||||||
};
|
};
|
||||||
|
|
||||||
Config_WiFi configWifi;
|
Config_WiFi configWifi;
|
||||||
|
|
|
@ -226,7 +226,7 @@ bool LoadConfig() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveConfig(bool writeToSerial = false) {
|
bool SaveConfig(bool writeToSerial = false) {
|
||||||
/*
|
/*
|
||||||
* Building config.json here
|
* Building config.json here
|
||||||
*/
|
*/
|
||||||
|
@ -289,7 +289,7 @@ void SaveConfig(bool writeToSerial = false) {
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
Serial.printf("!! [LittleFS:SaveConfig] FAILED to open configfile for writing: %s\n", CANGROW_CFG);
|
Serial.printf("!! [LittleFS:SaveConfig] FAILED to open configfile for writing: %s\n", CANGROW_CFG);
|
||||||
return;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
Serial.printf(":: [LittleFS:SaveConfig] opened for writing %s\n", CANGROW_CFG);
|
Serial.printf(":: [LittleFS:SaveConfig] opened for writing %s\n", CANGROW_CFG);
|
||||||
}
|
}
|
||||||
|
@ -307,7 +307,7 @@ void SaveConfig(bool writeToSerial = false) {
|
||||||
Serial.printf(":: [LittleFS:SaveConfig] --- %s ---\n", CANGROW_CFG);
|
Serial.printf(":: [LittleFS:SaveConfig] --- %s ---\n", CANGROW_CFG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,7 @@ bool TestHeaderFooter(const String& var) {
|
||||||
(var == "CGVER") ||
|
(var == "CGVER") ||
|
||||||
(var == "CGBUILD") ||
|
(var == "CGBUILD") ||
|
||||||
(var == "GROWNAME") ||
|
(var == "GROWNAME") ||
|
||||||
(var == "CANGROW_CSS")
|
(var == "CANGROW_CSS")) {
|
||||||
) {
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -32,3 +32,7 @@
|
||||||
const char Common_HTML_SAVE_MSG[] PROGMEM = R"EOF(
|
const char Common_HTML_SAVE_MSG[] PROGMEM = R"EOF(
|
||||||
<div class='infomsg'>✅ Successfully saved!</div>
|
<div class='infomsg'>✅ Successfully saved!</div>
|
||||||
)EOF";
|
)EOF";
|
||||||
|
|
||||||
|
const char Common_HTML_SAVE_MSG_ERR[] PROGMEM = R"EOF(
|
||||||
|
<div class='infomsg'>!! ERROR saving!</div>
|
||||||
|
)EOF";
|
||||||
|
|
|
@ -91,45 +91,120 @@ String Proc_WebPage_wifi_POST(const String& var) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String Proc_WebPage_wifi_POST_ERR(const String& var) {
|
||||||
|
if(var == "SAVE_MSG") {
|
||||||
|
return String(Common_HTML_SAVE_MSG_ERR);
|
||||||
|
} else {
|
||||||
|
return Proc_WebPage_wifi(var);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WebPage_wifi(AsyncWebServerRequest *request) {
|
void WebPage_wifi(AsyncWebServerRequest *request) {
|
||||||
if(request->hasParam("configWifi.ssid", true)) {
|
|
||||||
|
|
||||||
const AsyncWebParameter* p_ssid = request->getParam("configWifi.ssid", true);
|
if(request->method() == HTTP_POST) {
|
||||||
Serial.printf(":: [Webserver:wifi] POST[%s]: %s\n", p_ssid->name().c_str(), p_ssid->value().c_str());
|
if(request->hasParam("configWifi.ssid", true)) {
|
||||||
strlcpy(configWifi.ssid, p_ssid->value().c_str(), sizeof(configWifi.ssid));
|
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);
|
if(request->hasParam("configWifi.password", true)) {
|
||||||
const AsyncWebParameter* p_ip1 = request->getParam("configWifi.ip1", true);
|
const AsyncWebParameter* p_password = request->getParam("configWifi.password", true);
|
||||||
const AsyncWebParameter* p_ip2 = request->getParam("configWifi.ip2", true);
|
Serial.printf(":: [Webserver:wifi] POST[%s]: %s\n", p_password->name().c_str(), p_password->value().c_str());
|
||||||
const AsyncWebParameter* p_ip3 = request->getParam("configWifi.ip3", true);
|
strlcpy(configWifi.password, p_password->value().c_str(), sizeof(configWifi.password));
|
||||||
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);
|
if(
|
||||||
|
(request->hasParam("configWifi.ip0", true)) &&
|
||||||
|
(request->hasParam("configWifi.ip1", true)) &&
|
||||||
|
(request->hasParam("configWifi.ip2", true)) &&
|
||||||
|
(request->hasParam("configWifi.ip3", true))) {
|
||||||
|
|
||||||
|
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[configWifi.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(
|
||||||
|
(request->hasParam("configWifi.netmask0", true)) &&
|
||||||
|
(request->hasParam("configWifi.netmask1", true)) &&
|
||||||
|
(request->hasParam("configWifi.netmask2", true)) &&
|
||||||
|
(request->hasParam("configWifi.netmask3", true))) {
|
||||||
|
|
||||||
|
const AsyncWebParameter* p_netmask0 = request->getParam("configWifi.netmask0", true);
|
||||||
|
const AsyncWebParameter* p_netmask1 = request->getParam("configWifi.netmask1", true);
|
||||||
|
const AsyncWebParameter* p_netmask2 = request->getParam("configWifi.netmask2", true);
|
||||||
|
const AsyncWebParameter* p_netmask3 = request->getParam("configWifi.netmask3", true);
|
||||||
|
Serial.printf(":: [Webserver:wifi] POST[configWifi.netmask0-3]: %s . %s . %s . %s\n", p_netmask0->value().c_str(), p_netmask1->value().c_str(), p_netmask2->value().c_str(), p_netmask3->value().c_str());
|
||||||
|
configWifi.netmask[0] = p_netmask0->value().toInt();
|
||||||
|
configWifi.netmask[1] = p_netmask1->value().toInt();
|
||||||
|
configWifi.netmask[2] = p_netmask2->value().toInt();
|
||||||
|
configWifi.netmask[3] = p_netmask3->value().toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(
|
||||||
|
(request->hasParam("configWifi.gateway0", true)) &&
|
||||||
|
(request->hasParam("configWifi.gateway1", true)) &&
|
||||||
|
(request->hasParam("configWifi.gateway2", true)) &&
|
||||||
|
(request->hasParam("configWifi.gateway3", true))) {
|
||||||
|
|
||||||
|
const AsyncWebParameter* p_gateway0 = request->getParam("configWifi.gateway0", true);
|
||||||
|
const AsyncWebParameter* p_gateway1 = request->getParam("configWifi.gateway1", true);
|
||||||
|
const AsyncWebParameter* p_gateway2 = request->getParam("configWifi.gateway2", true);
|
||||||
|
const AsyncWebParameter* p_gateway3 = request->getParam("configWifi.gateway3", true);
|
||||||
|
Serial.printf(":: [Webserver:wifi] POST[configWifi.gateway0-3]: %s . %s . %s . %s\n", p_gateway0->value().c_str(), p_gateway1->value().c_str(), p_gateway2->value().c_str(), p_gateway3->value().c_str());
|
||||||
|
configWifi.gateway[0] = p_gateway0->value().toInt();
|
||||||
|
configWifi.gateway[1] = p_gateway1->value().toInt();
|
||||||
|
configWifi.gateway[2] = p_gateway2->value().toInt();
|
||||||
|
configWifi.gateway[3] = p_gateway3->value().toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(
|
||||||
|
(request->hasParam("configWifi.dns0", true)) &&
|
||||||
|
(request->hasParam("configWifi.dns1", true)) &&
|
||||||
|
(request->hasParam("configWifi.dns2", true)) &&
|
||||||
|
(request->hasParam("configWifi.dns3", true))) {
|
||||||
|
|
||||||
|
const AsyncWebParameter* p_dns0 = request->getParam("configWifi.dns0", true);
|
||||||
|
const AsyncWebParameter* p_dns1 = request->getParam("configWifi.dns1", true);
|
||||||
|
const AsyncWebParameter* p_dns2 = request->getParam("configWifi.dns2", true);
|
||||||
|
const AsyncWebParameter* p_dns3 = request->getParam("configWifi.dns3", true);
|
||||||
|
Serial.printf(":: [Webserver:wifi] POST[configWifi.dns0-3]: %s . %s . %s . %s\n", p_dns0->value().c_str(), p_dns1->value().c_str(), p_dns2->value().c_str(), p_dns3->value().c_str());
|
||||||
|
configWifi.dns[0] = p_dns0->value().toInt();
|
||||||
|
configWifi.dns[1] = p_dns1->value().toInt();
|
||||||
|
configWifi.dns[2] = p_dns2->value().toInt();
|
||||||
|
configWifi.dns[3] = p_dns3->value().toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(request->hasParam("configWifi.dhcp", true)) {
|
||||||
|
const AsyncWebParameter* p_dhcp = request->getParam("configWifi.dhcp", true);
|
||||||
|
Serial.printf(":: [Webserver:wifi] POST[%s]: %s\n", p_dhcp->name().c_str(), p_dhcp->value().c_str());
|
||||||
|
configWifi.dhcp = p_dhcp->value().toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SaveConfig()) {
|
||||||
|
Serial.println(":: [Webserver:wifi] config saved");
|
||||||
|
request->send_P(200, "text/html", Page_wifi_HTML, Proc_WebPage_wifi_POST);
|
||||||
|
} else {
|
||||||
|
Serial.println("!! [Webserver:wifi] ERROR saving config ");
|
||||||
|
request->send_P(200, "text/html", Page_wifi_HTML, Proc_WebPage_wifi_POST_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
request->send_P(200, "text/html", Page_wifi_HTML, Proc_WebPage_wifi);
|
request->send_P(200, "text/html", Page_wifi_HTML, Proc_WebPage_wifi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,29 @@ IP: <input class='inputShort' type='number' min='0' max='255' name='configWifi.i
|
||||||
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip2'> .
|
<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>
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.ip3'><br>
|
||||||
|
|
||||||
Subnet mask: <input type='text' name='configWifi.netmask'><br>
|
Subnet mask: <input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask0'> .
|
||||||
Gateway: <input type='text' name='configWifi.gateway'><br>
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask1'> .
|
||||||
DNS: <input type='text' name='configWifi.dns'><br>
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask2'> .
|
||||||
DHCP: <input type='checkbox' name='configWifi.dhcp' value='1'><br>
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.netmask3'><br>
|
||||||
|
|
||||||
|
Gateway: <input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway0'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway1'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway2'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.gateway3'><br>
|
||||||
|
|
||||||
|
DNS: <input class='inputShort' type='number' min='0' max='255' name='configWifi.dns0'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns1'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns2'> .
|
||||||
|
<input class='inputShort' type='number' min='0' max='255' name='configWifi.dns3'><br>
|
||||||
|
|
||||||
|
|
||||||
|
DHCP: <select name='configWifi.dhcp' required>
|
||||||
|
<option disabled value='' selected hidden>---</option>
|
||||||
|
<option value='1'>On</option>
|
||||||
|
<option value='0'>Off</option>
|
||||||
|
</select><br>
|
||||||
|
|
||||||
|
|
||||||
<input type='submit' value='💾 Save settings'>
|
<input type='submit' value='💾 Save settings'>
|
||||||
</form>
|
</form>
|
||||||
%FOOTER%)";
|
%FOOTER%)";
|
||||||
|
|
Loading…
Reference in a new issue