diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h
index d9de539..9bed8b4 100644
--- a/Arduino/CanGrow/include/CanGrow.h
+++ b/Arduino/CanGrow/include/CanGrow.h
@@ -50,7 +50,7 @@ struct Config_WiFi {
byte netmask[4] = {255,255,255,0};
byte gateway[4] = {192,168,4,255};
byte dns[4] = {0,0,0,0};
- bool dhcp = true;
+ bool dhcp;
};
Config_WiFi configWifi;
diff --git a/Arduino/CanGrow/include/CanGrow_LittleFS.h b/Arduino/CanGrow/include/CanGrow_LittleFS.h
index 9682113..8a79cbb 100644
--- a/Arduino/CanGrow/include/CanGrow_LittleFS.h
+++ b/Arduino/CanGrow/include/CanGrow_LittleFS.h
@@ -226,7 +226,7 @@ bool LoadConfig() {
return true;
}
-void SaveConfig(bool writeToSerial = false) {
+bool SaveConfig(bool writeToSerial = false) {
/*
* Building config.json here
*/
@@ -289,7 +289,7 @@ void SaveConfig(bool writeToSerial = false) {
if (!file) {
Serial.printf("!! [LittleFS:SaveConfig] FAILED to open configfile for writing: %s\n", CANGROW_CFG);
- return;
+ return false;
} else {
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);
}
-
+ return true;
}
diff --git a/Arduino/CanGrow/include/Webserver/Common.h b/Arduino/CanGrow/include/Webserver/Common.h
index a8ca683..43fd9b4 100644
--- a/Arduino/CanGrow/include/Webserver/Common.h
+++ b/Arduino/CanGrow/include/Webserver/Common.h
@@ -42,8 +42,7 @@ bool TestHeaderFooter(const String& var) {
(var == "CGVER") ||
(var == "CGBUILD") ||
(var == "GROWNAME") ||
- (var == "CANGROW_CSS")
- ) {
+ (var == "CANGROW_CSS")) {
return true;
} else {
return false;
diff --git a/Arduino/CanGrow/include/Webserver/Common_HTML.h b/Arduino/CanGrow/include/Webserver/Common_HTML.h
index 64f6aaf..3d87dc8 100644
--- a/Arduino/CanGrow/include/Webserver/Common_HTML.h
+++ b/Arduino/CanGrow/include/Webserver/Common_HTML.h
@@ -32,3 +32,7 @@
const char Common_HTML_SAVE_MSG[] PROGMEM = R"EOF(
✅ Successfully saved!
)EOF";
+
+const char Common_HTML_SAVE_MSG_ERR[] PROGMEM = R"EOF(
+!! ERROR saving!
+)EOF";
diff --git a/Arduino/CanGrow/include/Webserver/Page_wifi.h b/Arduino/CanGrow/include/Webserver/Page_wifi.h
index 5c356a2..6d58394 100644
--- a/Arduino/CanGrow/include/Webserver/Page_wifi.h
+++ b/Arduino/CanGrow/include/Webserver/Page_wifi.h
@@ -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) {
- if(request->hasParam("configWifi.ssid", true)) {
+
+ if(request->method() == HTTP_POST) {
+ 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_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);
+ if(request->hasParam("configWifi.password", true)) {
+ 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));
+ }
- 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 {
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 42dabbf..0856f31 100644
--- a/Arduino/CanGrow/include/Webserver/Page_wifi_HTML.h
+++ b/Arduino/CanGrow/include/Webserver/Page_wifi_HTML.h
@@ -50,10 +50,29 @@ IP: .
-Subnet mask:
-Gateway:
-DNS:
-DHCP:
+Subnet mask: .
+ .
+ .
+
+
+Gateway: .
+ .
+ .
+
+
+DNS: .
+ .
+ .
+
+
+
+DHCP:
+
+
%FOOTER%)";