MQTT publisher can set retain flag
Add this flag for IP adress publisher
This commit is contained in:
parent
d954883d19
commit
1166ef1a79
@ -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, ...){
|
||||||
|
Loading…
Reference in New Issue
Block a user