diff --git a/WifiControlSensor/MQTT.ino b/WifiControlSensor/MQTT.ino index 6f6d6e7..531ec8e 100644 --- a/WifiControlSensor/MQTT.ino +++ b/WifiControlSensor/MQTT.ino @@ -1,4 +1,5 @@ #include +#include "utils.h" #include "MQTT.h" Adafruit_MQTT_Client *mqtt; @@ -9,7 +10,6 @@ Adafruit_MQTT_Publish *mqtt_dht_humidity; Adafruit_MQTT_Publish *mqtt_dry; Adafruit_MQTT_Publish *mqtt_ip; -#define NB_ELEMENTS(x) (sizeof(x)/ sizeof(x[0])) #define FEED_MAX_SIZE 96 //FEED have the following formats /feeds/USER/DEVICE_NAME/.... diff --git a/WifiControlSensor/WebServer.ino b/WifiControlSensor/WebServer.ino index 6134958..105e00d 100644 --- a/WifiControlSensor/WebServer.ino +++ b/WifiControlSensor/WebServer.ino @@ -1,7 +1,18 @@ -#define STRINGIFY(x) #x -#define TOSTRING(x) STRINGIFY(x) +const int gpioWebConf[] = CONFIG_WEB_CONTROLLED_GPIO; void WebHandleRoot() { + String gpioWeb = ""; + + 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 += "
"; + } + server.send(200, "text/html", "" "

You are connected to " + String(hostName) + "

" @@ -18,15 +29,7 @@ void WebHandleRoot() { #ifdef CONFIG_ENABLE_DRY_SENSOR "Dryness " + String((dryness*100)/1024) + "%
" #endif - "" -#ifdef CONFIG_WEB_CONTROLLED_GPIO - "
" - "Relay" - "Relay ON
" - "Relay OFF
" - "
" -#endif - "
" + "
" + gpioWeb + "
" "Settings" "Enter Setup
" "Put device in OTA mode
" diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index 8e9db61..146c562 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -38,6 +38,7 @@ #include #include "config.h" +#include "utils.h" #include "debug_sketch.h" #include "BMP180.h" diff --git a/WifiControlSensor/config.h b/WifiControlSensor/config.h index fb70dd1..df3fdcb 100644 --- a/WifiControlSensor/config.h +++ b/WifiControlSensor/config.h @@ -39,6 +39,10 @@ #define CONFIG_SSID_NAME "ESPConfigurator" #endif +#ifndef CONFIG_WEB_CONTROLLED_GPIO +#define CONFIG_WEB_CONTROLLED_GPIO {} +#endif + #ifndef CONFIG_MQTT_CONTROLLED_GPIO #define CONFIG_MQTT_CONTROLLED_GPIO {} #endif diff --git a/WifiControlSensor/config_device.h b/WifiControlSensor/config_device.h index 0e3481b..4119d6c 100644 --- a/WifiControlSensor/config_device.h +++ b/WifiControlSensor/config_device.h @@ -26,7 +26,7 @@ #define CONFIG_ENABLE_MDNS //Web controlled GPIO -#define CONFIG_WEB_CONTROLLED_GPIO 2 +#define CONFIG_WEB_CONTROLLED_GPIO {2} /* DEFAULT VALUE ALSO DEFINED IN CONFIG.H */ diff --git a/WifiControlSensor/utils.h b/WifiControlSensor/utils.h new file mode 100644 index 0000000..0512751 --- /dev/null +++ b/WifiControlSensor/utils.h @@ -0,0 +1,6 @@ +#pragma once + +#define NB_ELEMENTS(x) (sizeof(x)/ sizeof(x[0])) + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x)