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;
void WebHandleRoot() {
String gpioWeb = "";
String gpioControlHTML = "";
if (NB_ELEMENTS(gpioWebConf) > 0){
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>";
}
void WebHandleRoot() {
server.send(200, "text/html",
"<head><meta http-equiv=\"refresh\" content=\"" + String(CONFIG_SAMPLING_PERIODE_MS / 1000) + "\" ></head>"
@ -29,7 +20,7 @@ void WebHandleRoot() {
#ifdef CONFIG_ENABLE_DRY_SENSOR
"Dryness " + String((dryness*100)/1024) + "%<br/>"
#endif
"</fieldset>" + gpioWeb + "<fieldset>"
"</fieldset>" + gpioControlHTML + "<fieldset>"
"<legend>Settings</legend>"
"<a href=\"/setup\">Enter Setup</a><br/>"
"<a href=\"/otamode\">Put device in OTA mode</a><br/>"
@ -244,7 +235,21 @@ void WebHandleWifiStatus() {
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 ) {
WebBuildGpioControl();
server.on("/", WebHandleRoot);
server.on("/setup", WebHandleSetup);
server.on("/save", WebHandleSave);