Merge branch 'mqtt_retain' into 'master'
Mqtt retain See merge request !7
This commit is contained in:
commit
f31c5f3854
@ -2,7 +2,7 @@
|
|||||||
#ifndef CONFIG_DISABLE_MQTT
|
#ifndef CONFIG_DISABLE_MQTT
|
||||||
#include "Adafruit_MQTT.h"
|
#include "Adafruit_MQTT.h"
|
||||||
typedef struct {uint8_t updated; int value;} gpioInfo;
|
typedef struct {uint8_t updated; int value;} gpioInfo;
|
||||||
Adafruit_MQTT_Publish *MqttCreatePublisher(const char *fmt, ...);
|
Adafruit_MQTT_Publish *MqttCreatePublisher(uint8_t qos, uint8_t retain, const char *fmt, ...);
|
||||||
int MqttConnect();
|
int MqttConnect();
|
||||||
int MqttIsConnected();
|
int MqttIsConnected();
|
||||||
int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname);
|
int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname);
|
||||||
|
@ -52,12 +52,12 @@ int MqttSetup(char *server, char *user, char *passwd, int port, char *hostname)
|
|||||||
#endif
|
#endif
|
||||||
mqtt = new Adafruit_MQTT_Client(new WiFiClient(), server, port, user, passwd);
|
mqtt = new Adafruit_MQTT_Client(new WiFiClient(), server, port, user, passwd);
|
||||||
|
|
||||||
mqtt_dht_temp = MqttCreatePublisher(TEMPERATURE_DHT_FEED_FORMAT, user, mqttId);
|
mqtt_dht_temp = MqttCreatePublisher(0, 0, TEMPERATURE_DHT_FEED_FORMAT, user, mqttId);
|
||||||
mqtt_dht_humidity = MqttCreatePublisher(HUMIDITY_DHT_FEED_FORMAT, user, mqttId);
|
mqtt_dht_humidity = MqttCreatePublisher(0, 0, HUMIDITY_DHT_FEED_FORMAT, user, mqttId);
|
||||||
mqtt_temp = MqttCreatePublisher(TEMPERATURE_FEED_FORMAT, user, mqttId);
|
mqtt_temp = MqttCreatePublisher(0, 0, TEMPERATURE_FEED_FORMAT, user, mqttId);
|
||||||
mqtt_pressure = MqttCreatePublisher(PRESSURE_FEED_FORMAT, user, mqttId);
|
mqtt_pressure = MqttCreatePublisher(0, 0, PRESSURE_FEED_FORMAT, user, mqttId);
|
||||||
mqtt_dry = MqttCreatePublisher(DRY_FEED_FORMAT, user, mqttId);
|
mqtt_dry = MqttCreatePublisher(0, 0, DRY_FEED_FORMAT, user, mqttId);
|
||||||
mqtt_ip = MqttCreatePublisher(IP_FEED_FORMAT, user, mqttId);
|
mqtt_ip = MqttCreatePublisher(0, 1, IP_FEED_FORMAT, user, mqttId);
|
||||||
|
|
||||||
if (NB_ELEMENTS(gpioControlled) + NB_ELEMENTS(pwmControlled) > MAXSUBSCRIPTIONS){
|
if (NB_ELEMENTS(gpioControlled) + NB_ELEMENTS(pwmControlled) > 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",
|
||||||
@ -72,29 +72,29 @@ int MqttSetup(char *server, char *user, char *passwd, int port, char *hostname)
|
|||||||
|
|
||||||
for (uint i = 0 ; i < NB_ELEMENTS(gpioControlled); i++) {
|
for (uint i = 0 ; i < NB_ELEMENTS(gpioControlled); i++) {
|
||||||
mqtt->subscribe(MqttCreateSubscribe(GPIO_SET_FEED_FORMAT, user, mqttId, gpioControlled[i]));
|
mqtt->subscribe(MqttCreateSubscribe(GPIO_SET_FEED_FORMAT, user, mqttId, gpioControlled[i]));
|
||||||
mqttGpio[i] = MqttCreatePublisher(GPIO_FEED_FORMAT, user, mqttId, gpioControlled[i]);
|
mqttGpio[i] = MqttCreatePublisher(0, 0, GPIO_FEED_FORMAT, user, mqttId, gpioControlled[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint i = 0 ; i < NB_ELEMENTS(gpioObserved) && i < MAX_GPIO_OBSERVED ; i++) {
|
for (uint i = 0 ; i < NB_ELEMENTS(gpioObserved) && i < MAX_GPIO_OBSERVED ; i++) {
|
||||||
mqttGpioObserved[i] = MqttCreatePublisher(GPIO_FEED_FORMAT, user, mqttId, gpioObserved[i]);
|
mqttGpioObserved[i] = MqttCreatePublisher(0, 0, GPIO_FEED_FORMAT, user, mqttId, gpioObserved[i]);
|
||||||
new HIB(gpioObserved[i], HIGH, MqttNofityIRQ , MqttNofityIRQ, NULL );
|
new HIB(gpioObserved[i], HIGH, MqttNofityIRQ , MqttNofityIRQ, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint i = 0 ; i < NB_ELEMENTS(pwmControlled); i++) {
|
for (uint i = 0 ; i < NB_ELEMENTS(pwmControlled); i++) {
|
||||||
mqtt->subscribe(MqttCreateSubscribe(PWM_SET_FEED_FORMAT, user, mqttId, pwmControlled[i]));
|
mqtt->subscribe(MqttCreateSubscribe(PWM_SET_FEED_FORMAT, user, mqttId, pwmControlled[i]));
|
||||||
mqttPwm[i] = MqttCreatePublisher(PWM_FEED_FORMAT, user, mqttId, pwmControlled[i]);
|
mqttPwm[i] = MqttCreatePublisher(0, 0, PWM_FEED_FORMAT, user, mqttId, pwmControlled[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Adafruit_MQTT_Publish *MqttCreatePublisher(const char *fmt, ...){
|
Adafruit_MQTT_Publish *MqttCreatePublisher( uint8_t qos, uint8_t retain, const char *fmt, ...){
|
||||||
char buf[FEED_MAX_SIZE];
|
char buf[FEED_MAX_SIZE];
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, fmt);
|
va_start (args, fmt);
|
||||||
vsnprintf(buf, sizeof(buf), (const char *)fmt, args);
|
vsnprintf(buf, sizeof(buf), (const char *)fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return new Adafruit_MQTT_Publish(mqtt, strdup(buf));
|
return new Adafruit_MQTT_Publish(mqtt, strdup(buf), qos, retain);
|
||||||
}
|
}
|
||||||
|
|
||||||
Adafruit_MQTT_Subscribe *MqttCreateSubscribe(const char *fmt, ...){
|
Adafruit_MQTT_Subscribe *MqttCreateSubscribe(const char *fmt, ...){
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
#define CONFIG_BMP180_SCL 14
|
#define CONFIG_BMP180_SCL 14
|
||||||
|
|
||||||
#define CONFIG_ENABLE_DHT
|
#define CONFIG_ENABLE_DHT
|
||||||
#define CONFIG_DHT_PIN 5
|
#define CONFIG_DHT_PIN 2
|
||||||
|
#define CONFIG_DHT_TYPE DHT22
|
||||||
|
|
||||||
//#define CONFIG_ENABLE_DRY_SENSOR
|
//#define CONFIG_ENABLE_DRY_SENSOR
|
||||||
//If the dry sensor is powered by a GPIO, this GPIO could be defined here
|
//If the dry sensor is powered by a GPIO, this GPIO could be defined here
|
||||||
@ -37,24 +38,24 @@
|
|||||||
|
|
||||||
/* DEFAULT VALUE ALSO DEFINED IN CONFIG.H */
|
/* DEFAULT VALUE ALSO DEFINED IN CONFIG.H */
|
||||||
//If this GPIO is LOW at boot, device will enter setup mode
|
//If this GPIO is LOW at boot, device will enter setup mode
|
||||||
//#define CONFIG_SETUP_GPIO 3
|
#define CONFIG_SETUP_GPIO 5
|
||||||
|
|
||||||
// Time to sleep between 2 webserver request (increase it reduce battery usage but increase latency)
|
// Time to sleep between 2 webserver request (increase it reduce battery usage but increase latency)
|
||||||
//#define CONFIG_WEB_DELAY_MS 100
|
//#define CONFIG_WEB_DELAY_MS 100
|
||||||
|
|
||||||
// Get sensors value every X ms
|
// Get sensors value every X ms
|
||||||
//#define CONFIG_SAMPLING_PERIODE_MS 60000
|
#define CONFIG_SAMPLING_PERIODE_MS 300000
|
||||||
|
|
||||||
// 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 "ESPConfiguratorBureau"
|
||||||
|
|
||||||
// GPIO that can be set or get by mqtt and set via http
|
// 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_CONTROLLED_GPIO {2,13}
|
//#define CONFIG_CONTROLLED_GPIO {12,13}
|
||||||
|
|
||||||
// GPIO that can be get by mqtt and http
|
// GPIO that can be get by mqtt and http
|
||||||
// Pin 6 to 11 and 16 can not be used for mqtt
|
// Pin 6 to 11 and 16 can not be used for mqtt
|
||||||
#define CONFIG_OBSERVED_GPIO {5}
|
//#define CONFIG_OBSERVED_GPIO {5}
|
||||||
|
|
||||||
// GPIO used in PWM
|
// GPIO used in PWM
|
||||||
//#define CONFIG_CONTROLLED_PWM {}
|
//#define CONFIG_CONTROLLED_PWM {}
|
||||||
|
Loading…
Reference in New Issue
Block a user