Use Array to define GPIO controlled by Web
This commit is contained in:
parent
979bb58a4b
commit
1a7b3ec53a
@ -1,4 +1,5 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include "utils.h"
|
||||||
#include "MQTT.h"
|
#include "MQTT.h"
|
||||||
|
|
||||||
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
|
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
|
||||||
@ -11,7 +12,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/....
|
||||||
|
@ -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]) + "&value=1\">ON</a>/";
|
||||||
|
gpioWeb += "<a href=\"/gpio?gpio=" + String(gpioWebConf[i]) + "&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) "&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/>"
|
||||||
|
@ -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"
|
||||||
|
@ -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
|
||||||
|
@ -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 */
|
||||||
|
6
WifiControlSensor/utils.h
Normal file
6
WifiControlSensor/utils.h
Normal 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)
|
Loading…
Reference in New Issue
Block a user