Build HTML to control GPIO one time only

This commit is contained in:
Mathieu Maret 2016-09-28 15:28:02 +02:00
parent c911376cce
commit 0ccf653cc6

View File

@ -1,17 +1,8 @@
const int gpioWebConf[] = CONFIG_WEB_CONTROLLED_GPIO; const int gpioWebConf[] = CONFIG_WEB_CONTROLLED_GPIO;
void WebHandleRoot() { String gpioControlHTML = "";
String gpioWeb = "";
if (NB_ELEMENTS(gpioWebConf) > 0){ void WebHandleRoot() {
gpioWeb += "<fieldset>"
"<legend>Relay</legend>";
for (uint i = 0 ; i < NB_ELEMENTS(gpioWebConf) ; i++) {
gpioWeb += "Relay " + String(gpioWebConf[i]) + " " + "<a href=\"/gpio?gpio=" + String(gpioWebConf[i]) + "&amp;value=1\">ON</a>/";
gpioWeb += "<a href=\"/gpio?gpio=" + String(gpioWebConf[i]) + "&amp;value=0\">OFF</a><br/>";
}
gpioWeb += "</fieldset>";
}
server.send(200, "text/html", server.send(200, "text/html",
"<head><meta http-equiv=\"refresh\" content=\"" + String(CONFIG_SAMPLING_PERIODE_MS / 1000) + "\" ></head>" "<head><meta http-equiv=\"refresh\" content=\"" + String(CONFIG_SAMPLING_PERIODE_MS / 1000) + "\" ></head>"
@ -29,7 +20,7 @@ void WebHandleRoot() {
#ifdef CONFIG_ENABLE_DRY_SENSOR #ifdef CONFIG_ENABLE_DRY_SENSOR
"Dryness " + String((dryness*100)/1024) + "%<br/>" "Dryness " + String((dryness*100)/1024) + "%<br/>"
#endif #endif
"</fieldset>" + gpioWeb + "<fieldset>" "</fieldset>" + gpioControlHTML + "<fieldset>"
"<legend>Settings</legend>" "<legend>Settings</legend>"
"<a href=\"/setup\">Enter Setup</a><br/>" "<a href=\"/setup\">Enter Setup</a><br/>"
"<a href=\"/otamode\">Put device in OTA mode</a><br/>" "<a href=\"/otamode\">Put device in OTA mode</a><br/>"
@ -244,7 +235,21 @@ void WebHandleWifiStatus() {
server.send(200, "text/html", message); server.send(200, "text/html", message);
} }
void WebBuildGpioControl(){
if (NB_ELEMENTS(gpioWebConf) > 0){
gpioControlHTML += "<fieldset>"
"<legend>Relay</legend>";
for (uint i = 0 ; i < NB_ELEMENTS(gpioWebConf) ; i++) {
gpioControlHTML += "Relay " + String(gpioWebConf[i]) + " " + "<a href=\"/gpio?gpio=" + String(gpioWebConf[i]) + "&amp;value=1\">ON</a>/";
gpioControlHTML += "<a href=\"/gpio?gpio=" + String(gpioWebConf[i]) + "&amp;value=0\">OFF</a><br/>";
}
gpioControlHTML += "</fieldset>";
}
}
void WebSetupServer(int ) { void WebSetupServer(int ) {
WebBuildGpioControl();
server.on("/", WebHandleRoot); server.on("/", WebHandleRoot);
server.on("/setup", WebHandleSetup); server.on("/setup", WebHandleSetup);
server.on("/save", WebHandleSave); server.on("/save", WebHandleSave);