All controlled gpio have a single config entry
They get be set/get by mqtt and set by http
This commit is contained in:
parent
1a2d3a3eb6
commit
13c2d23330
@ -29,7 +29,7 @@ Adafruit_MQTT_Publish *mqttPwm[MAXSUBSCRIPTIONS] = {};
|
|||||||
|
|
||||||
// Should have less that MAXSUBSCRIPTIONS elements
|
// Should have less that MAXSUBSCRIPTIONS elements
|
||||||
// MAXSUBSCRIPTIONS is defined is Adafruit_mqtt.h
|
// MAXSUBSCRIPTIONS is defined is Adafruit_mqtt.h
|
||||||
const int gpioWatched[] = CONFIG_MQTT_CONTROLLED_GPIO;
|
const int gpioControlled[] = CONFIG_CONTROLLED_GPIO;
|
||||||
const int pwmWatched[] = CONFIG_CONTROLLED_PWM;
|
const int pwmWatched[] = CONFIG_CONTROLLED_PWM;
|
||||||
|
|
||||||
char *mqttId;
|
char *mqttId;
|
||||||
@ -60,18 +60,18 @@ int MqttSetup(char *server, char *user, char *passwd, int port, char *hostname)
|
|||||||
mqtt_dry = MqttCreatePublisher(DRY_FEED_FORMAT, user, mqttId);
|
mqtt_dry = MqttCreatePublisher(DRY_FEED_FORMAT, user, mqttId);
|
||||||
mqtt_ip = MqttCreatePublisher(IP_FEED_FORMAT, user, mqttId);
|
mqtt_ip = MqttCreatePublisher(IP_FEED_FORMAT, user, mqttId);
|
||||||
|
|
||||||
if( NB_ELEMENTS(gpioWatched) + NB_ELEMENTS(pwmWatched) > MAXSUBSCRIPTIONS){
|
if( NB_ELEMENTS(gpioControlled) + NB_ELEMENTS(pwmWatched) > MAXSUBSCRIPTIONS){
|
||||||
SKETCH_DEBUG_PRINTF("Too much gpio/pwm to control\n Nb gpio %d Nb pwm %d Max is %d",
|
SKETCH_DEBUG_PRINTF("Too much gpio/pwm to control\n Nb gpio %d Nb pwm %d Max is %d",
|
||||||
NB_ELEMENTS(gpioWatched), NB_ELEMENTS(pwmWatched), MAXSUBSCRIPTIONS);
|
NB_ELEMENTS(gpioControlled), NB_ELEMENTS(pwmWatched), MAXSUBSCRIPTIONS);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint i = 0 ; i < NB_ELEMENTS(gpioWatched) && i < MAXSUBSCRIPTIONS; i++) {
|
for (uint i = 0 ; i < NB_ELEMENTS(gpioControlled) && i < MAXSUBSCRIPTIONS; i++) {
|
||||||
mqtt->subscribe(MqttCreateSubscribe(GPIO_SET_FEED_FORMAT, user, mqttId, gpioWatched[i]));
|
mqtt->subscribe(MqttCreateSubscribe(GPIO_SET_FEED_FORMAT, user, mqttId, gpioControlled[i]));
|
||||||
mqttGpio[i] = MqttCreatePublisher(GPIO_FEED_FORMAT, user, mqttId, gpioWatched[i]);
|
mqttGpio[i] = MqttCreatePublisher(GPIO_FEED_FORMAT, user, mqttId, gpioControlled[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint i = 0 ; i < NB_ELEMENTS(gpioWatched) && i < MAXSUBSCRIPTIONS; i++) {
|
for (uint i = 0 ; i < NB_ELEMENTS(gpioControlled) && i < MAXSUBSCRIPTIONS; i++) {
|
||||||
mqtt->subscribe(MqttCreateSubscribe(PWM_SET_FEED_FORMAT, user, mqttId, pwmWatched[i]));
|
mqtt->subscribe(MqttCreateSubscribe(PWM_SET_FEED_FORMAT, user, mqttId, pwmWatched[i]));
|
||||||
mqttPwm[i] = MqttCreatePublisher(PWM_FEED_FORMAT, user, mqttId, pwmWatched[i]);
|
mqttPwm[i] = MqttCreatePublisher(PWM_FEED_FORMAT, user, mqttId, pwmWatched[i]);
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ int getGpioFromSubscription(Adafruit_MQTT_Subscribe *subscription, const char *p
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MqttNofity(int gpio, int value){
|
void MqttNofity(int gpio, int value){
|
||||||
int watchIdx = findIndex(gpio, gpioWatched);
|
int watchIdx = findIndex(gpio, gpioControlled);
|
||||||
if (watchIdx >= 0 && isMqttConfigured) {
|
if (watchIdx >= 0 && isMqttConfigured) {
|
||||||
mqttGpio[watchIdx]->publish(value);
|
mqttGpio[watchIdx]->publish(value);
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ void MqttCheckSubscription() {
|
|||||||
Adafruit_MQTT_Subscribe *subscription;
|
Adafruit_MQTT_Subscribe *subscription;
|
||||||
while ((subscription = mqtt->readSubscription(0))) {
|
while ((subscription = mqtt->readSubscription(0))) {
|
||||||
int gpio = getGpioFromSubscription(subscription, "/gpio/");
|
int gpio = getGpioFromSubscription(subscription, "/gpio/");
|
||||||
if (gpio > 0 && findIndex(gpio, gpioWatched) >= 0) {
|
if (gpio > 0 && findIndex(gpio, gpioControlled) >= 0) {
|
||||||
SKETCH_DEBUG_PRINTF("Got Subscription for GPIO %d\n", gpio);
|
SKETCH_DEBUG_PRINTF("Got Subscription for GPIO %d\n", gpio);
|
||||||
char *value = (char *) subscription->lastread;
|
char *value = (char *) subscription->lastread;
|
||||||
SKETCH_DEBUG_PRINTF("Receive data: %s\n", value);
|
SKETCH_DEBUG_PRINTF("Receive data: %s\n", value);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef CONFIG_DISABLE_WEB
|
#ifndef CONFIG_DISABLE_WEB
|
||||||
const int gpioWebConf[] = CONFIG_WEB_CONTROLLED_GPIO;
|
const int gpioWebConf[] = CONFIG_CONTROLLED_GPIO;
|
||||||
const int pwmWebConf[] = CONFIG_CONTROLLED_PWM;
|
const int pwmWebConf[] = CONFIG_CONTROLLED_PWM;
|
||||||
|
|
||||||
String gpioControlHTML = "";
|
String gpioControlHTML = "";
|
||||||
|
@ -47,8 +47,8 @@
|
|||||||
#define CONFIG_WEB_CONTROLLED_GPIO {}
|
#define CONFIG_WEB_CONTROLLED_GPIO {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_MQTT_CONTROLLED_GPIO
|
#ifndef CONFIG_CONTROLLED_GPIO
|
||||||
#define CONFIG_MQTT_CONTROLLED_GPIO {}
|
#define CONFIG_CONTROLLED_GPIO {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_EEPROM_SIZE
|
#ifndef CONFIG_EEPROM_SIZE
|
||||||
|
@ -31,12 +31,6 @@
|
|||||||
// Disable mDNS can also save power
|
// Disable mDNS can also save power
|
||||||
#define CONFIG_ENABLE_MDNS
|
#define CONFIG_ENABLE_MDNS
|
||||||
|
|
||||||
// Web controlled GPIO
|
|
||||||
#define CONFIG_WEB_CONTROLLED_GPIO {2}
|
|
||||||
|
|
||||||
// GPIO used in PWM
|
|
||||||
#define CONFIG_CONTROLLED_PWM {}
|
|
||||||
|
|
||||||
// Long press on this button will put device in setup mode at runtime
|
// Long press on this button will put device in setup mode at runtime
|
||||||
#define CONFIG_SETUP_BUTTON 0
|
#define CONFIG_SETUP_BUTTON 0
|
||||||
|
|
||||||
@ -54,9 +48,12 @@
|
|||||||
// Name of the SSID when in AP mode for configuration
|
// Name of the SSID when in AP mode for configuration
|
||||||
//#define CONFIG_SSID_NAME "ESPConfigurator"
|
//#define CONFIG_SSID_NAME "ESPConfigurator"
|
||||||
|
|
||||||
// GPIO that can be set or get by mqtt
|
// GPIO that can be set or get by mqtt and set via http
|
||||||
// Should have less value than MAXSUBSCRIPTIONS
|
// Should have less value than MAXSUBSCRIPTIONS
|
||||||
#define CONFIG_MQTT_CONTROLLED_GPIO {2,13}
|
#define CONFIG_CONTROLLED_GPIO {2,13}
|
||||||
|
|
||||||
|
// GPIO used in PWM
|
||||||
|
//#define CONFIG_CONTROLLED_PWM {}
|
||||||
|
|
||||||
// EEPROM SIZE
|
// EEPROM SIZE
|
||||||
// Max is 4096, but this amount will be allocated in RAM for reading its content
|
// Max is 4096, but this amount will be allocated in RAM for reading its content
|
||||||
|
Loading…
Reference in New Issue
Block a user