Merge branch 'master' of github.com:adafruit/Adafruit_MQTT_Library

Conflicts:
	Adafruit_MQTT.h
This commit is contained in:
ladyada 2015-05-31 23:21:00 -04:00
commit 495f2cddd5
2 changed files with 17 additions and 7 deletions

View File

@ -1,7 +1,7 @@
#include "Adafruit_MQTT.h"
Adafruit_MQTT::Adafruit_MQTT(char *server, uint16_t port, char *user, char *key) {
Adafruit_MQTT::Adafruit_MQTT(char *server, uint16_t port, char *user, char *key, char *cid) {
strncpy(servername, server, SERVERNAME_SIZE);
servername[SERVERNAME_SIZE-1] = 0;
portnum = port;
@ -9,7 +9,9 @@ Adafruit_MQTT::Adafruit_MQTT(char *server, uint16_t port, char *user, char *key)
strncpy(username, user, USERNAME_SIZE);
username[USERNAME_SIZE-1] = 0;
strncpy(userkey, key, KEY_SIZE);
userkey[KEY_SIZE-1] = 0;
userkey[KEY_SIZE-1] = 0;
strncpy(clientid, cid, CLIENTID_SIZE);
userkey[CLIENTID_SIZE-1] = 0;
errno = 0;
}
@ -24,9 +26,9 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
// fill in packet[1] last
p[0] = 0;
p[1] = 6; // (strlen(MQIdsp)
p[1] = 6; // (strlen(MQIsdp)
p+=2;
memcpy(p,"MQIdsp", 6);
memcpy(p,"MQIsdp", 6);
p+=6;
p[0] = MQTT_PROTOCOL_LEVEL;
@ -45,15 +47,21 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
p[0] = MQTT_CONN_KEEPALIVE & 0xFF;
p++;
uint16_t len = strlen(clientid);
p[0] = len >> 8; p++;
p[0] = len & 0xFF; p++;
memcpy(p, clientid, len);
p+=len;
if (username[0] != 0) {
uint16_t len = strlen(username);
len = strlen(username);
p[0] = len >> 8; p++;
p[0] = len & 0xFF; p++;
memcpy(p, username, len);
p+=len;
}
if (userkey[0] != 0) {
uint16_t len = strlen(userkey);
len = strlen(userkey);
p[0] = len >> 8; p++;
p[0] = len & 0xFF; p++;
memcpy(p, userkey, len);

View File

@ -19,7 +19,8 @@
#define SERVERNAME_SIZE 25
#define USERNAME_SIZE 25
#define KEY_SIZE 41
#define FEEDNAME_SIZE 65
#define FEEDNAME_SIZE 25
#define CLIENTID_SIZE 23
#define CONNECT_TIMEOUT_MS 3000
#define PUBLISH_TIMEOUT_MS 500
@ -47,6 +48,7 @@ class Adafruit_MQTT {
char servername[SERVERNAME_SIZE];
uint32_t serverip;
int16_t portnum;
char clientid[CLIENTID_SIZE];
char username[USERNAME_SIZE];
char userkey[KEY_SIZE];