|
@ -16,6 +16,7 @@ class mqtt { |
|
|
mClient = new PubSubClient(mEspClient); |
|
|
mClient = new PubSubClient(mEspClient); |
|
|
mAddressSet = false; |
|
|
mAddressSet = false; |
|
|
|
|
|
|
|
|
|
|
|
memset(mAddr, 0, MQTT_ADDR_LEN); |
|
|
memset(mUser, 0, MQTT_USER_LEN); |
|
|
memset(mUser, 0, MQTT_USER_LEN); |
|
|
memset(mPwd, 0, MQTT_PWD_LEN); |
|
|
memset(mPwd, 0, MQTT_PWD_LEN); |
|
|
memset(mTopic, 0, MQTT_TOPIC_LEN); |
|
|
memset(mTopic, 0, MQTT_TOPIC_LEN); |
|
@ -23,13 +24,14 @@ class mqtt { |
|
|
|
|
|
|
|
|
~mqtt() { } |
|
|
~mqtt() { } |
|
|
|
|
|
|
|
|
void setup(const char *broker, const char *topic, const char *user, const char *pwd, uint16_t port) { |
|
|
void setup(const char *addr, const char *topic, const char *user, const char *pwd, uint16_t port) { |
|
|
DPRINTLN(DBG_VERBOSE, F("mqtt.h:setup")); |
|
|
DPRINTLN(DBG_VERBOSE, F("mqtt.h:setup")); |
|
|
mAddressSet = true; |
|
|
mAddressSet = true; |
|
|
mClient->setServer(broker, port); |
|
|
mClient->setServer(addr, port); |
|
|
mClient->setBufferSize(MQTT_MAX_PACKET_SIZE); |
|
|
mClient->setBufferSize(MQTT_MAX_PACKET_SIZE); |
|
|
|
|
|
|
|
|
mPort = port; |
|
|
mPort = port; |
|
|
|
|
|
snprintf(mAddr, MQTT_ADDR_LEN, "%s", addr); |
|
|
snprintf(mUser, MQTT_USER_LEN, "%s", user); |
|
|
snprintf(mUser, MQTT_USER_LEN, "%s", user); |
|
|
snprintf(mPwd, MQTT_PWD_LEN, "%s", pwd); |
|
|
snprintf(mPwd, MQTT_PWD_LEN, "%s", pwd); |
|
|
snprintf(mTopic, MQTT_TOPIC_LEN, "%s", topic); |
|
|
snprintf(mTopic, MQTT_TOPIC_LEN, "%s", topic); |
|
@ -58,6 +60,11 @@ class mqtt { |
|
|
return mClient->connected(); |
|
|
return mClient->connected(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char *getAddr(void) { |
|
|
|
|
|
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:getAddr"));
|
|
|
|
|
|
return mAddr; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
char *getUser(void) { |
|
|
char *getUser(void) { |
|
|
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:getUser"));
|
|
|
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:getUser"));
|
|
|
return mUser; |
|
|
return mUser; |
|
@ -88,10 +95,12 @@ class mqtt { |
|
|
void reconnect(void) { |
|
|
void reconnect(void) { |
|
|
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:reconnect"));
|
|
|
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:reconnect"));
|
|
|
if(!mClient->connected()) { |
|
|
if(!mClient->connected()) { |
|
|
|
|
|
if(strlen(mAddr) > 0) { |
|
|
if((strlen(mUser) > 0) && (strlen(mPwd) > 0)) |
|
|
if((strlen(mUser) > 0) && (strlen(mPwd) > 0)) |
|
|
mClient->connect(DEF_DEVICE_NAME, mUser, mPwd); |
|
|
mClient->connect(mAddr, mUser, mPwd); |
|
|
else |
|
|
else |
|
|
mClient->connect(DEF_DEVICE_NAME); |
|
|
mClient->connect(mAddr); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -100,6 +109,7 @@ class mqtt { |
|
|
|
|
|
|
|
|
bool mAddressSet; |
|
|
bool mAddressSet; |
|
|
uint16_t mPort; |
|
|
uint16_t mPort; |
|
|
|
|
|
char mAddr[MQTT_ADDR_LEN]; |
|
|
char mUser[MQTT_USER_LEN]; |
|
|
char mUser[MQTT_USER_LEN]; |
|
|
char mPwd[MQTT_PWD_LEN]; |
|
|
char mPwd[MQTT_PWD_LEN]; |
|
|
char mTopic[MQTT_TOPIC_LEN]; |
|
|
char mTopic[MQTT_TOPIC_LEN]; |
|
|