diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino
index 7f25471..aaa5177 100644
--- a/Arduino/CanGrow/CanGrow.ino
+++ b/Arduino/CanGrow/CanGrow.ino
@@ -157,6 +157,7 @@ void loop() {
Serial.println(":: [LOOP] save output 0");
byte i = 0;
config.system.output.type[i] = 1;
+ config.system.output.device[i] = 1;
strlcpy(config.system.output.name[i], "bla", sizeof("bla"));
config.system.output.gpio[i] = 3;
config.system.output.gpio_invert[i] = false;
@@ -172,6 +173,7 @@ void loop() {
Serial.println(":: [LOOP] save output 1");
i = 1;
config.system.output.type[i] = 2;
+ config.system.output.device[i] = 3;
strlcpy(config.system.output.name[i], "lol", sizeof("lol"));
config.system.output.gpio[i] = 5;
config.system.output.gpio_invert[i] = true;
@@ -181,7 +183,7 @@ void loop() {
for(byte j=0; j < 4 ; j++) {
config.system.output.ip[i][j] = j + 23;
}
- strlcpy(config.system.output.ip_path[i], "/asd?foo=lol", sizeof("/asd?foo=lol"));
+ strlcpy(config.system.output.ip_path[i], "/toggle_switch?on=true", sizeof("/toggle_switch?on=true"));
config.system.output.enabled[i] = true;
// save config to littlefs as json
diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h
index 9850e7a..bf35b17 100644
--- a/Arduino/CanGrow/include/CanGrow.h
+++ b/Arduino/CanGrow/include/CanGrow.h
@@ -109,6 +109,13 @@ struct Config_System_Output {
* 1 - GPIO
* 2 - I2C
* 3 - URL
+ * - device: what this output is connected to
+ * 1 - Light
+ * 2 - Fan
+ * 3 - Pump
+ * 4 - Humudifier
+ * 5 - Dehumidifier
+ * 6 - Heating
* - gpio: which gpio is used
* - gpio_invert: invert gpio output
* - gpio_pwm: enable pwm for output
@@ -119,6 +126,7 @@ struct Config_System_Output {
*
*/
byte type[Max_Outputs];
+ byte device[Max_Outputs];
char name[Max_Outputs][32];
byte gpio[Max_Outputs];
bool gpio_invert[Max_Outputs];
diff --git a/Arduino/CanGrow/include/CanGrow_LittleFS.h b/Arduino/CanGrow/include/CanGrow_LittleFS.h
index 032c38a..e1daaee 100644
--- a/Arduino/CanGrow/include/CanGrow_LittleFS.h
+++ b/Arduino/CanGrow/include/CanGrow_LittleFS.h
@@ -211,6 +211,7 @@ bool LoadConfig() {
for(byte i=0; i < Max_Outputs; i++) {
if(objSystemOutput["type"][i] > 0) {
config.system.output.type[i] = objSystemOutput["type"][i];
+ config.system.output.device[i] = objSystemOutput["device"][i];
strlcpy(config.system.output.name[i], objSystemOutput["name"][i], sizeof(config.system.output.name[i]));
config.system.output.gpio[i] = objSystemOutput["gpio"][i];
config.system.output.gpio_invert[i] = objSystemOutput["gpio_invert"][i];
@@ -288,6 +289,7 @@ bool SaveConfig(bool writeToSerial = false) {
for(byte i=0; i < Max_Outputs; i++) {
if(config.system.output.type[i] > 0) {
objSystemOutput["type"][i] = config.system.output.type[i];
+ objSystemOutput["device"][i] = config.system.output.device[i];
objSystemOutput["name"][i] = config.system.output.name[i];
objSystemOutput["gpio"][i] = config.system.output.gpio[i];
objSystemOutput["gpio_invert"][i] = config.system.output.gpio_invert[i];
diff --git a/Arduino/CanGrow/include/CanGrow_Webserver.h b/Arduino/CanGrow/include/CanGrow_Webserver.h
index ba139f3..3213e39 100644
--- a/Arduino/CanGrow/include/CanGrow_Webserver.h
+++ b/Arduino/CanGrow/include/CanGrow_Webserver.h
@@ -99,6 +99,9 @@ void Webserver_Init() {
webserver.on("/system/wipe", HTTP_GET, WebPage_system_wipe);
webserver.on("/system/wipe", HTTP_POST, WebPage_system_wipe);
+ webserver.on("/system/output", HTTP_GET, WebPage_system_output);
+ webserver.on("/system/output", HTTP_POST, WebPage_system_output);
+
requestLogger.setOutput(Serial);
// this activates the middleware
if(config.system.httpLogSerial == true) {
diff --git a/Arduino/CanGrow/include/Webserver/Common_HTML.h b/Arduino/CanGrow/include/Webserver/Common_HTML.h
index 72c98e1..ecc0604 100644
--- a/Arduino/CanGrow/include/Webserver/Common_HTML.h
+++ b/Arduino/CanGrow/include/Webserver/Common_HTML.h
@@ -39,7 +39,7 @@ const char Common_HTML_SAVE_MSG_ERR[] PROGMEM = R"EOF(
const char Common_HTML_NEED_RESTART[] PROGMEM = R"EOF(
❗ Restart is required to apply new settings!
-
diff --git a/Arduino/CanGrow/include/Webserver/Page_system.h b/Arduino/CanGrow/include/Webserver/Page_system.h
index dc1e953..379c17a 100644
--- a/Arduino/CanGrow/include/Webserver/Page_system.h
+++ b/Arduino/CanGrow/include/Webserver/Page_system.h
@@ -36,15 +36,66 @@
String Proc_WebPage_system(const String& var) {
if(TestHeaderFooter(var)) {
return AddHeaderFooter(var);
- } else if(var == "LOL") {
- return String("Nice");
+ } else if(var == "SUBNAV") {
+ return String(Page_system_HTML_SUBNAV);
} else {
return String();
}
}
+String Proc_WebPage_system_POST(const String& var) {
+ if(var == "SUBNAV") {
+ return String(Page_system_HTML_SUBNAV);
+ } else if(var == "SAVE_MSG") {
+ return String(Common_HTML_SAVE_MSG);
+ } else {
+ return Proc_WebPage_system(var);
+ }
+}
+
+String Proc_WebPage_system_POST_ERR(const String& var) {
+ if(var == "SUBNAV") {
+ return String(Page_system_HTML_SUBNAV);
+ } else if(var == "SAVE_MSG") {
+ return String(Common_HTML_SAVE_MSG_ERR);
+ } else {
+ return Proc_WebPage_system(var);
+ }
+}
+
void WebPage_system(AsyncWebServerRequest *request) {
- request->send_P(200, "text/html", Page_system_HTML, Proc_WebPage_system);
+ if(request->method() == HTTP_POST) {
+ request->send_P(200, "text/html", Page_system_HTML, Proc_WebPage_system_POST);
+ Serial.println(":: [Webserver:system:output] [POST] hello");
+
+
+ if(request->hasParam("config.system.ntpOffset", true)) {
+ const AsyncWebParameter* p_ntpOffset = request->getParam("config.system.ntpOffset", true);
+ Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_ntpOffset->name().c_str(), p_ntpOffset->value().c_str());
+ config.system.ntpOffset = p_ntpOffset->value().toInt();
+ }
+
+ if(request->hasParam("config.system.httpLogSerial", true)) {
+ const AsyncWebParameter* p_httpLogSerial = request->getParam("config.system.httpLogSerial", true);
+ Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_httpLogSerial->name().c_str(), p_httpLogSerial->value().c_str());
+ config.system.httpLogSerial = p_httpLogSerial->value().toInt();
+ }
+
+ if(SaveConfig()) {
+ // we need a restart to apply the new settings
+ needRestart = true;
+ Serial.println(":: [Webserver:system] config saved");
+ request->send_P(200, "text/html", Page_wifi_HTML, Proc_WebPage_system_POST);
+ } else {
+ Serial.println("!! [Webserver:system] ERROR saving config ");
+ request->send_P(200, "text/html", Page_wifi_HTML, Proc_WebPage_system_POST_ERR);
+ }
+
+
+
+ } else {
+ request->send_P(200, "text/html", Page_system_HTML, Proc_WebPage_system);
+ }
}
@@ -71,6 +122,9 @@ String Proc_WebPage_system_restart_POST(const String& var) {
void WebPage_system_restart(AsyncWebServerRequest *request) {
if(request->method() == HTTP_POST) {
+ if(request->hasParam("confirmed", true)) {
+ doRestart = false;
+ }
request->send_P(200, "text/html", Page_system_restart_HTML, Proc_WebPage_system_restart_POST);
if(request->hasParam("confirmed", true)) {
@@ -184,3 +238,37 @@ void WebPage_system_wipe(AsyncWebServerRequest *request) {
}
+
+/*
+ * Subpage output
+ */
+String Proc_WebPage_system_output(const String& var) {
+ if(TestHeaderFooter(var)) {
+ return AddHeaderFooter(var);
+ } else if(var == "SUBNAV") {
+ return String(Page_system_HTML_SUBNAV);
+ } else{
+ return String();
+ }
+}
+
+String Proc_WebPage_system_output_POST(const String& var) {
+ if(var == "SAVE_MSG") {
+ return String(Common_HTML_SAVE_MSG);
+ } else {
+ return Proc_WebPage_system_output(var);
+ }
+}
+
+void WebPage_system_output(AsyncWebServerRequest *request) {
+ if(request->method() == HTTP_POST) {
+ request->send_P(200, "text/html", Page_system_output_HTML, Proc_WebPage_system_output_POST);
+ Serial.println(":: [Webserver:system:output] [POST] hello");
+
+
+ } else {
+ request->send_P(200, "text/html", Page_system_output_HTML, Proc_WebPage_system_output);
+ }
+
+}
+
diff --git a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h
index 86e1620..d6c2849 100644
--- a/Arduino/CanGrow/include/Webserver/Page_system_HTML.h
+++ b/Arduino/CanGrow/include/Webserver/Page_system_HTML.h
@@ -31,48 +31,35 @@
const char* Page_system_HTML PROGMEM = R"(%HEADER%
⚙ System settings
-
-here you can set which features and sensors you use