Browse Source

mqtt disconnect

main
Hendrik Langer 5 years ago
parent
commit
14977542cb
  1. 11
      src/network/XD0MQTT.cpp
  2. 1
      src/network/XD0MQTT.h

11
src/network/XD0MQTT.cpp

@ -117,6 +117,17 @@ bool XD0MQTT::begin(void) {
return true; 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) { 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); int msg_id = esp_mqtt_client_publish(client, topic, data, len, qos, retain);
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id); ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);

1
src/network/XD0MQTT.h

@ -29,6 +29,7 @@ class XD0MQTT {
public: public:
XD0MQTT(void); XD0MQTT(void);
bool begin(void); bool begin(void);
void end(void);
bool publish(const char* topic, const char* data, int len, int qos=1, int retain=0); 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 publishf(const char* topic, const char* format, ...);
bool publishf2(const char* topic, int qos, int retain, const char* format, ...); bool publishf2(const char* topic, int qos, int retain, const char* format, ...);

Loading…
Cancel
Save