Merge branch 'WebGpioArray' into 'master'

Use Array to define GPIO controlled by Web



See merge request !3
This commit is contained in:
Mathieu 2016-09-20 18:30:00 +02:00
commit 83afc2e845
6 changed files with 27 additions and 13 deletions

View File

@ -1,4 +1,5 @@
#include <stdarg.h> #include <stdarg.h>
#include "utils.h"
#include "MQTT.h" #include "MQTT.h"
Adafruit_MQTT_Client *mqtt; Adafruit_MQTT_Client *mqtt;
@ -9,7 +10,6 @@ Adafruit_MQTT_Publish *mqtt_dht_humidity;
Adafruit_MQTT_Publish *mqtt_dry; Adafruit_MQTT_Publish *mqtt_dry;
Adafruit_MQTT_Publish *mqtt_ip; Adafruit_MQTT_Publish *mqtt_ip;
#define NB_ELEMENTS(x) (sizeof(x)/ sizeof(x[0]))
#define FEED_MAX_SIZE 96 #define FEED_MAX_SIZE 96
//FEED have the following formats /feeds/USER/DEVICE_NAME/.... //FEED have the following formats /feeds/USER/DEVICE_NAME/....

View File

@ -1,7 +1,18 @@
#define STRINGIFY(x) #x const int gpioWebConf[] = CONFIG_WEB_CONTROLLED_GPIO;
#define TOSTRING(x) STRINGIFY(x)
void WebHandleRoot() { void WebHandleRoot() {
String gpioWeb = "";
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>";
}
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>"
"<h1>You are connected to " + String(hostName) + "</h1>" "<h1>You are connected to " + String(hostName) + "</h1>"
@ -18,15 +29,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>" "</fieldset>" + gpioWeb + "<fieldset>"
#ifdef CONFIG_WEB_CONTROLLED_GPIO
"<fieldset>"
"<legend>Relay</legend>"
"<a href=\"/gpio?gpio=" TOSTRING(CONFIG_WEB_CONTROLLED_GPIO) "&amp;value=1\">Relay ON</a><br/>"
"<a href=\"/gpio?gpio=" TOSTRING(CONFIG_WEB_CONTROLLED_GPIO) "&value=0\">Relay OFF</a><br/>"
"</fieldset>"
#endif
"<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/>"

View File

@ -38,6 +38,7 @@
#include <errno.h> #include <errno.h>
#include "config.h" #include "config.h"
#include "utils.h"
#include "debug_sketch.h" #include "debug_sketch.h"
#include "BMP180.h" #include "BMP180.h"

View File

@ -39,6 +39,10 @@
#define CONFIG_SSID_NAME "ESPConfigurator" #define CONFIG_SSID_NAME "ESPConfigurator"
#endif #endif
#ifndef CONFIG_WEB_CONTROLLED_GPIO
#define CONFIG_WEB_CONTROLLED_GPIO {}
#endif
#ifndef CONFIG_MQTT_CONTROLLED_GPIO #ifndef CONFIG_MQTT_CONTROLLED_GPIO
#define CONFIG_MQTT_CONTROLLED_GPIO {} #define CONFIG_MQTT_CONTROLLED_GPIO {}
#endif #endif

View File

@ -26,7 +26,7 @@
#define CONFIG_ENABLE_MDNS #define CONFIG_ENABLE_MDNS
//Web controlled GPIO //Web controlled GPIO
#define CONFIG_WEB_CONTROLLED_GPIO 2 #define CONFIG_WEB_CONTROLLED_GPIO {2}
/* DEFAULT VALUE ALSO DEFINED IN CONFIG.H */ /* DEFAULT VALUE ALSO DEFINED IN CONFIG.H */

View File

@ -0,0 +1,6 @@
#pragma once
#define NB_ELEMENTS(x) (sizeof(x)/ sizeof(x[0]))
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)