Add MQTT 3.1.1 support

This commit is contained in:
Nick O'Leary 2015-08-26 23:07:22 +01:00
parent c1a522102d
commit c753ecaebe
2 changed files with 15 additions and 3 deletions

View File

@ -66,11 +66,18 @@ boolean PubSubClient::connect(char *id, char *user, char *pass, char* willTopic,
if (result) { if (result) {
nextMsgId = 1; nextMsgId = 1;
uint8_t d[9] = {0x00,0x06,'M','Q','I','s','d','p',MQTTPROTOCOLVERSION};
// Leave room in the buffer for header and variable length field // Leave room in the buffer for header and variable length field
uint16_t length = 5; uint16_t length = 5;
unsigned int j; unsigned int j;
for (j = 0;j<9;j++) {
#if MQTT_VERSION == MQTT_VERSION_3_1
uint8_t d[9] = {0x00,0x06,'M','Q','I','s','d','p', MQTT_VERSION};
#define MQTT_HEADER_VERSION_LENGTH 9
#elif MQTT_VERSION == MQTT_VERSION_3_1_1
uint8_t d[7] = {0x00,0x04,'M','Q','T','T',MQTT_VERSION};
#define MQTT_HEADER_VERSION_LENGTH 7
#endif
for (j = 0;j<MQTT_HEADER_VERSION_LENGTH;j++) {
buffer[length++] = d[j]; buffer[length++] = d[j];
} }

View File

@ -11,13 +11,18 @@
#include "Client.h" #include "Client.h"
#include "Stream.h" #include "Stream.h"
#define MQTT_VERSION_3_1 3
#define MQTT_VERSION_3_1_1 4
// MQTT_VERSION
#define MQTT_VERSION MQTT_VERSION_3_1_1
// MQTT_MAX_PACKET_SIZE : Maximum packet size // MQTT_MAX_PACKET_SIZE : Maximum packet size
#define MQTT_MAX_PACKET_SIZE 128 #define MQTT_MAX_PACKET_SIZE 128
// MQTT_KEEPALIVE : keepAlive interval in Seconds // MQTT_KEEPALIVE : keepAlive interval in Seconds
#define MQTT_KEEPALIVE 15 #define MQTT_KEEPALIVE 15
#define MQTTPROTOCOLVERSION 3
#define MQTTCONNECT 1 << 4 // Client request to connect to Server #define MQTTCONNECT 1 << 4 // Client request to connect to Server
#define MQTTCONNACK 2 << 4 // Connect Acknowledgment #define MQTTCONNACK 2 << 4 // Connect Acknowledgment
#define MQTTPUBLISH 3 << 4 // Publish message #define MQTTPUBLISH 3 << 4 // Publish message