From 14977542cbdcd2f40eccb95d8556c178eb24c051 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Fri, 9 Aug 2019 16:17:06 +0200 Subject: [PATCH] mqtt disconnect --- src/network/XD0MQTT.cpp | 11 +++++++++++ src/network/XD0MQTT.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/network/XD0MQTT.cpp b/src/network/XD0MQTT.cpp index 339ad12..8b1e7e1 100644 --- a/src/network/XD0MQTT.cpp +++ b/src/network/XD0MQTT.cpp @@ -117,6 +117,17 @@ bool XD0MQTT::begin(void) { return true; } +void XD0MQTT::end(void) { + //for (const auto &subscription : subscriptions_) { + // int msg_id = esp_mqtt_client_unsubscribe(client, subscription.topic); + // ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id); + //} + subscriptions_.clear(); + esp_mqtt_client_stop(client); + delay(10); + esp_mqtt_client_destroy(client); +} + bool XD0MQTT::publish(const char* topic, const char* data, int len, int qos, int retain) { int msg_id = esp_mqtt_client_publish(client, topic, data, len, qos, retain); ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id); diff --git a/src/network/XD0MQTT.h b/src/network/XD0MQTT.h index 1f0fba5..a4699fd 100644 --- a/src/network/XD0MQTT.h +++ b/src/network/XD0MQTT.h @@ -29,6 +29,7 @@ class XD0MQTT { public: XD0MQTT(void); bool begin(void); + void end(void); bool publish(const char* topic, const char* data, int len, int qos=1, int retain=0); bool publishf(const char* topic, const char* format, ...); bool publishf2(const char* topic, int qos, int retain, const char* format, ...);