adds will support to the connect packet

This commit is contained in:
Todd Treece 2015-10-05 09:45:27 -04:00
parent e60be3e972
commit e9e154ab52
2 changed files with 21 additions and 1 deletions

View File

@ -276,13 +276,29 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
p[0] = MQTT_PROTOCOL_LEVEL; p[0] = MQTT_PROTOCOL_LEVEL;
p++; p++;
// always clean the session
p[0] = MQTT_CONN_CLEANSESSION; p[0] = MQTT_CONN_CLEANSESSION;
// set the will flags if needed
if (pgm_read_byte(will_topic) != 0) {
p[0] |= MQTT_CONN_WILLFLAG;
if(will_qos == 1)
p[0] |= MQTT_CONN_WILLQOS_1;
else if(will_qos == 2)
p[0] |= MQTT_CONN_WILLQOS_2;
if(will_retain == 1)
p[0] |= MQTT_CONN_WILLRETAIN;
}
if (pgm_read_byte(username) != 0) if (pgm_read_byte(username) != 0)
p[0] |= MQTT_CONN_USERNAMEFLAG; p[0] |= MQTT_CONN_USERNAMEFLAG;
if (pgm_read_byte(password) != 0) if (pgm_read_byte(password) != 0)
p[0] |= MQTT_CONN_PASSWORDFLAG; p[0] |= MQTT_CONN_PASSWORDFLAG;
p++; p++;
// TODO: add WILL support?
p[0] = MQTT_CONN_KEEPALIVE >> 8; p[0] = MQTT_CONN_KEEPALIVE >> 8;
p++; p++;

View File

@ -189,6 +189,10 @@ class Adafruit_MQTT {
const char *clientid; const char *clientid;
const char *username; const char *username;
const char *password; const char *password;
const char *will_topic;
const char *will_payload;
uint8_t will_qos;
uint8_t will_retain;
uint8_t buffer[MAXBUFFERSIZE]; // one buffer, used for all incoming/outgoing uint8_t buffer[MAXBUFFERSIZE]; // one buffer, used for all incoming/outgoing
private: private: