mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
if mqtt disconnected save memory
This commit is contained in:
@@ -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
|
// add to MQTT queue as a subscribe operation
|
||||||
auto message = queue_subscribe_message(topic);
|
auto message = queue_subscribe_message(topic);
|
||||||
|
|
||||||
|
if (message == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// register in our libary with the callback function.
|
// register in our libary with the callback function.
|
||||||
// We store both the original topic and the fully-qualified one
|
// 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));
|
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
|
// 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) {
|
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 nullptr;
|
||||||
};
|
};
|
||||||
return queue_message(Operation::PUBLISH, topic, payload, retain);
|
return queue_message(Operation::PUBLISH, topic, payload, retain);
|
||||||
|
|||||||
Reference in New Issue
Block a user