Merge branch 'master' of github.com:adafruit/Adafruit_MQTT_Library
Conflicts: Adafruit_MQTT.h
This commit is contained in:
commit
495f2cddd5
@ -1,7 +1,7 @@
|
|||||||
#include "Adafruit_MQTT.h"
|
#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);
|
strncpy(servername, server, SERVERNAME_SIZE);
|
||||||
servername[SERVERNAME_SIZE-1] = 0;
|
servername[SERVERNAME_SIZE-1] = 0;
|
||||||
portnum = port;
|
portnum = port;
|
||||||
@ -9,7 +9,9 @@ Adafruit_MQTT::Adafruit_MQTT(char *server, uint16_t port, char *user, char *key)
|
|||||||
strncpy(username, user, USERNAME_SIZE);
|
strncpy(username, user, USERNAME_SIZE);
|
||||||
username[USERNAME_SIZE-1] = 0;
|
username[USERNAME_SIZE-1] = 0;
|
||||||
strncpy(userkey, key, KEY_SIZE);
|
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;
|
errno = 0;
|
||||||
}
|
}
|
||||||
@ -24,9 +26,9 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
|
|||||||
// fill in packet[1] last
|
// fill in packet[1] last
|
||||||
|
|
||||||
p[0] = 0;
|
p[0] = 0;
|
||||||
p[1] = 6; // (strlen(MQIdsp)
|
p[1] = 6; // (strlen(MQIsdp)
|
||||||
p+=2;
|
p+=2;
|
||||||
memcpy(p,"MQIdsp", 6);
|
memcpy(p,"MQIsdp", 6);
|
||||||
p+=6;
|
p+=6;
|
||||||
|
|
||||||
p[0] = MQTT_PROTOCOL_LEVEL;
|
p[0] = MQTT_PROTOCOL_LEVEL;
|
||||||
@ -45,15 +47,21 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
|
|||||||
p[0] = MQTT_CONN_KEEPALIVE & 0xFF;
|
p[0] = MQTT_CONN_KEEPALIVE & 0xFF;
|
||||||
p++;
|
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) {
|
if (username[0] != 0) {
|
||||||
uint16_t len = strlen(username);
|
len = strlen(username);
|
||||||
p[0] = len >> 8; p++;
|
p[0] = len >> 8; p++;
|
||||||
p[0] = len & 0xFF; p++;
|
p[0] = len & 0xFF; p++;
|
||||||
memcpy(p, username, len);
|
memcpy(p, username, len);
|
||||||
p+=len;
|
p+=len;
|
||||||
}
|
}
|
||||||
if (userkey[0] != 0) {
|
if (userkey[0] != 0) {
|
||||||
uint16_t len = strlen(userkey);
|
len = strlen(userkey);
|
||||||
p[0] = len >> 8; p++;
|
p[0] = len >> 8; p++;
|
||||||
p[0] = len & 0xFF; p++;
|
p[0] = len & 0xFF; p++;
|
||||||
memcpy(p, userkey, len);
|
memcpy(p, userkey, len);
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
#define SERVERNAME_SIZE 25
|
#define SERVERNAME_SIZE 25
|
||||||
#define USERNAME_SIZE 25
|
#define USERNAME_SIZE 25
|
||||||
#define KEY_SIZE 41
|
#define KEY_SIZE 41
|
||||||
#define FEEDNAME_SIZE 65
|
#define FEEDNAME_SIZE 25
|
||||||
|
#define CLIENTID_SIZE 23
|
||||||
|
|
||||||
#define CONNECT_TIMEOUT_MS 3000
|
#define CONNECT_TIMEOUT_MS 3000
|
||||||
#define PUBLISH_TIMEOUT_MS 500
|
#define PUBLISH_TIMEOUT_MS 500
|
||||||
@ -47,6 +48,7 @@ class Adafruit_MQTT {
|
|||||||
char servername[SERVERNAME_SIZE];
|
char servername[SERVERNAME_SIZE];
|
||||||
uint32_t serverip;
|
uint32_t serverip;
|
||||||
int16_t portnum;
|
int16_t portnum;
|
||||||
|
char clientid[CLIENTID_SIZE];
|
||||||
char username[USERNAME_SIZE];
|
char username[USERNAME_SIZE];
|
||||||
char userkey[KEY_SIZE];
|
char userkey[KEY_SIZE];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user