adds disconnect & disconnectPacket functions

This commit is contained in:
Todd Treece 2015-10-05 14:18:31 -04:00
parent 16da46aece
commit 4ab72be73e

View File

@ -155,6 +155,18 @@ const __FlashStringHelper* Adafruit_MQTT::connectErrorString(int8_t code) {
}
}
bool Adafruit_MQTT::disconnect() {
// Construct and send disconnect packet.
uint8_t len = disconnectPacket(buffer);
if (! sendPacket(buffer, len))
DEBUG_PRINTLN(F("Unable to send disconnect packet"));
return disconnectServer();
}
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos) {
// Construct and send publish packet.
uint8_t len = publishPacket(buffer, topic, data, qos);
@ -499,6 +511,14 @@ uint8_t Adafruit_MQTT::pingPacket(uint8_t *packet) {
return 2;
}
uint8_t Adafruit_MQTT::disconnectPacket(uint8_t *packet) {
packet[0] = MQTT_CTRL_DISCONNECT << 4;
packet[1] = 0;
DEBUG_PRINTLN(F("MQTT disconnect packet:"));
DEBUG_PRINTBUFFER(buffer, 2);
return 2;
}
// Adafruit_MQTT_Publish Definition ////////////////////////////////////////////