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