From 998de8b3c115cf61147d8e5ee6c85ae1c7f8a450 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Mon, 30 Nov 2020 17:01:45 +0100 Subject: [PATCH] if mqtt disconnected save memory --- src/mqtt.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 9be2cd84a..e711cef95 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -74,6 +74,10 @@ void Mqtt::subscribe(const uint8_t device_type, const std::string & topic, mqtt_ // add to MQTT queue as a subscribe operation auto message = queue_subscribe_message(topic); + if (message == nullptr) { + return; + } + // register in our libary with the callback function. // We store both the original topic and the fully-qualified one mqtt_subfunctions_.emplace_back(device_type, std::move(topic), std::move(message->topic), std::move(cb)); @@ -556,7 +560,7 @@ std::shared_ptr Mqtt::queue_message(const uint8_t operation, // add MQTT message to queue, payload is a string std::shared_ptr Mqtt::queue_publish_message(const std::string & topic, const std::string & payload, bool retain) { - if (!enabled()) { + if (!enabled() || !connected()) { return nullptr; }; return queue_message(Operation::PUBLISH, topic, payload, retain);