prevent duplicate MQTT connections

This commit is contained in:
proddy
2020-11-15 14:25:17 +01:00
parent 8db542b117
commit 88135ad277
2 changed files with 17 additions and 8 deletions

View File

@@ -85,6 +85,8 @@ class Mqtt {
static constexpr uint8_t MQTT_TOPIC_MAX_SIZE = 128; // note this should really match the user setting in mqttSettings.maxTopicLength
static void on_connect();
static void subscribe(const uint8_t device_type, const std::string & topic, mqtt_subfunction_p cb);
static void subscribe(const std::string & topic, mqtt_subfunction_p cb);
static void resubscribe();
@@ -112,7 +114,6 @@ class Mqtt {
static void show_topic_handlers(uuid::console::Shell & shell, const uint8_t device_type);
static void show_mqtt(uuid::console::Shell & shell);
static void on_connect();
static void ha_status();
void disconnect() {
@@ -189,8 +190,6 @@ class Mqtt {
void on_message(const char * topic, const char * payload, size_t len);
void process_queue();
static uint16_t mqtt_publish_fails_;
// function handlers for MQTT subscriptions
struct MQTTSubFunction {
uint8_t device_type_; // which device type, from DeviceType::
@@ -216,6 +215,9 @@ class Mqtt {
uint32_t last_publish_other_ = 0;
uint32_t last_publish_sensor_ = 0;
static bool connecting_;
static uint16_t mqtt_publish_fails_;
// settings, copied over
static std::string hostname_;
static uint8_t mqtt_qos_;