From b07e5f80582fbe232ce71370433fd320ed819b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Grome=C5=A1?= Date: Mon, 9 Jul 2018 11:14:57 +0200 Subject: [PATCH] ESP8266 - Implemented MQTT disconnect --- src/modules/ESP8266.cpp | 13 +++++++++++++ src/modules/ESP8266.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/modules/ESP8266.cpp b/src/modules/ESP8266.cpp index 54d7860b..ad319de8 100644 --- a/src/modules/ESP8266.cpp +++ b/src/modules/ESP8266.cpp @@ -412,6 +412,19 @@ uint8_t ESP8266::MqttConnect(const char* host, const char* clientId, const char* return(ERR_RESPONSE_MALFORMED); } +uint8_t ESP8266::MqttDisconnect() { + // build the DISCONNECT packet + uint8_t packet[2]; + + // fixed header + packet[0] = (MQTT_DISCONNECT << 4); + packet[1] = 0x00; + + // send MQTT packet + uint8_t state = send(packet, 2); + return(state); +} + uint8_t ESP8266::MqttPublish(const char* topic, const char* message) { // encode packet length size_t topicLen = strlen(topic); diff --git a/src/modules/ESP8266.h b/src/modules/ESP8266.h index 3dd1764a..a57c5e8c 100644 --- a/src/modules/ESP8266.h +++ b/src/modules/ESP8266.h @@ -44,6 +44,7 @@ class ESP8266 { // MQTT methods uint8_t MqttConnect(const char* host, const char* clientId, const char* userName = "", const char* password = "", uint16_t keepAlive = 60, bool cleanSession = true, const char* willTopic = "", const char* willMessage = ""); + uint8_t MqttDisconnect(); uint8_t MqttPublish(const char* topic, const char* message); // Transport layer methods