From 0ccf653cc669191adc47a9f0a11759d3a756370b Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 28 Sep 2016 15:28:02 +0200 Subject: [PATCH] Build HTML to control GPIO one time only --- WifiControlSensor/WebServer.ino | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/WifiControlSensor/WebServer.ino b/WifiControlSensor/WebServer.ino index cd77263..fa6f716 100644 --- a/WifiControlSensor/WebServer.ino +++ b/WifiControlSensor/WebServer.ino @@ -1,17 +1,8 @@ const int gpioWebConf[] = CONFIG_WEB_CONTROLLED_GPIO; -void WebHandleRoot() { - String gpioWeb = ""; +String gpioControlHTML = ""; - if (NB_ELEMENTS(gpioWebConf) > 0){ - gpioWeb += "
" - "Relay"; - for (uint i = 0 ; i < NB_ELEMENTS(gpioWebConf) ; i++) { - gpioWeb += "Relay " + String(gpioWebConf[i]) + " " + "ON/"; - gpioWeb += "OFF
"; - } - gpioWeb += "
"; - } +void WebHandleRoot() { server.send(200, "text/html", "" @@ -29,7 +20,7 @@ void WebHandleRoot() { #ifdef CONFIG_ENABLE_DRY_SENSOR "Dryness " + String((dryness*100)/1024) + "%
" #endif - "" + gpioWeb + "
" + "
" + gpioControlHTML + "
" "Settings" "Enter Setup
" "Put device in OTA mode
" @@ -244,7 +235,21 @@ void WebHandleWifiStatus() { server.send(200, "text/html", message); } +void WebBuildGpioControl(){ + if (NB_ELEMENTS(gpioWebConf) > 0){ + gpioControlHTML += "
" + "Relay"; + for (uint i = 0 ; i < NB_ELEMENTS(gpioWebConf) ; i++) { + gpioControlHTML += "Relay " + String(gpioWebConf[i]) + " " + "ON/"; + gpioControlHTML += "OFF
"; + } + gpioControlHTML += "
"; + } +} + void WebSetupServer(int ) { + WebBuildGpioControl(); + server.on("/", WebHandleRoot); server.on("/setup", WebHandleSetup); server.on("/save", WebHandleSave);