adds MQTT 3.1.1 connect packet changes

This commit is contained in:
Todd Treece 2015-10-02 10:45:00 -04:00
parent ea779b1daa
commit a3925bdb6b

View File

@ -96,25 +96,6 @@ Adafruit_MQTT::Adafruit_MQTT(const __FlashStringHelper *server, uint16_t port, c
} }
} }
/*
Adafruit_MQTT::Adafruit_MQTT(char *server, uint16_t port, char *cid, char *user, char *pass) {
strncpy(servername, server, SERVERNAME_SIZE);
servername[SERVERNAME_SIZE-1] = 0;
portnum = port;
serverip = 0;
strncpy(clientid, cid, CLIENTID_SIZE);
clientid[CLIENTID_SIZE-1] = 0;
strncpy(username, user, USERNAME_SIZE);
username[USERNAME_SIZE-1] = 0;
strncpy(password, pass, PASSWORD_SIZE);
password[PASSWORD_SIZE-1] = 0;
}
*/
int8_t Adafruit_MQTT::connect() { int8_t Adafruit_MQTT::connect() {
// Connect to the server. // Connect to the server.
if (!connectServer()) if (!connectServer())
@ -287,7 +268,10 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
p+=2; p+=2;
// fill in packet[1] last // fill in packet[1] last
if(MQTT_PROTOCOL_LEVEL == 3)
p = stringprint_P(p, PSTR("MQIsdp")); p = stringprint_P(p, PSTR("MQIsdp"));
else
p = stringprint_P(p, PSTR("MQTT"));
p[0] = MQTT_PROTOCOL_LEVEL; p[0] = MQTT_PROTOCOL_LEVEL;
p++; p++;
@ -305,7 +289,13 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
p[0] = MQTT_CONN_KEEPALIVE & 0xFF; p[0] = MQTT_CONN_KEEPALIVE & 0xFF;
p++; p++;
if(MQTT_PROTOCOL_LEVEL == 3) {
p = stringprint_P(p, clientid, 23); // Limit client ID to first 23 characters. p = stringprint_P(p, clientid, 23); // Limit client ID to first 23 characters.
} else {
if (pgm_read_byte(clientid) != 0) {
p = stringprint_P(p, clientid);
}
}
if (pgm_read_byte(username) != 0) { if (pgm_read_byte(username) != 0) {
p = stringprint_P(p, username); p = stringprint_P(p, username);