adds client id to connect
This commit is contained in:
parent
1bcef195f1
commit
e7b8ee0797
@ -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;
|
||||||
}
|
}
|
||||||
@ -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);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#define USERNAME_SIZE 25
|
#define USERNAME_SIZE 25
|
||||||
#define KEY_SIZE 41
|
#define KEY_SIZE 41
|
||||||
#define FEEDNAME_SIZE 25
|
#define FEEDNAME_SIZE 25
|
||||||
|
#define CLIENTID_SIZE 23
|
||||||
|
|
||||||
#define CONNECT_TIMEOUT_MS 3000
|
#define CONNECT_TIMEOUT_MS 3000
|
||||||
|
|
||||||
@ -38,6 +39,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