if mqtt disconnected save memory

This commit is contained in:
MichaelDvP
2020-11-30 17:01:45 +01:00
parent bf0c966c11
commit 998de8b3c1

View File

@@ -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<const MqttMessage> Mqtt::queue_message(const uint8_t operation,
// add MQTT message to queue, payload is a string
std::shared_ptr<const MqttMessage> 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);