|
@ -28,6 +28,7 @@ String mqttTopic; |
|
|
bool _mqttForward; |
|
|
bool _mqttForward; |
|
|
char *_mqttUser = 0; |
|
|
char *_mqttUser = 0; |
|
|
char *_mqttPass = 0; |
|
|
char *_mqttPass = 0; |
|
|
|
|
|
char *_mqttWill; |
|
|
std::vector<void (*)(unsigned int, const char *, const char *)> _mqtt_callbacks; |
|
|
std::vector<void (*)(unsigned int, const char *, const char *)> _mqtt_callbacks; |
|
|
#if MQTT_SKIP_RETAINED
|
|
|
#if MQTT_SKIP_RETAINED
|
|
|
unsigned long mqttConnectedAt = 0; |
|
|
unsigned long mqttConnectedAt = 0; |
|
@ -264,7 +265,8 @@ void mqttConnect() { |
|
|
unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt(); |
|
|
unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt(); |
|
|
_mqttUser = strdup(getSetting("mqttUser").c_str()); |
|
|
_mqttUser = strdup(getSetting("mqttUser").c_str()); |
|
|
_mqttPass = strdup(getSetting("mqttPassword").c_str()); |
|
|
_mqttPass = strdup(getSetting("mqttPassword").c_str()); |
|
|
char * will = strdup((mqttTopic + MQTT_TOPIC_STATUS).c_str()); |
|
|
|
|
|
|
|
|
if (_mqttWill) free(_mqttWill); |
|
|
|
|
|
_mqttWill = strdup((mqttTopic + MQTT_TOPIC_STATUS).c_str()); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[MQTT] Connecting to broker at %s:%d"), host, port); |
|
|
DEBUG_MSG_P(PSTR("[MQTT] Connecting to broker at %s:%d"), host, port); |
|
|
mqtt.setServer(host, port); |
|
|
mqtt.setServer(host, port); |
|
@ -272,7 +274,7 @@ void mqttConnect() { |
|
|
#if MQTT_USE_ASYNC
|
|
|
#if MQTT_USE_ASYNC
|
|
|
|
|
|
|
|
|
mqtt.setKeepAlive(MQTT_KEEPALIVE).setCleanSession(false); |
|
|
mqtt.setKeepAlive(MQTT_KEEPALIVE).setCleanSession(false); |
|
|
mqtt.setWill(will, MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
|
|
|
|
|
|
mqtt.setWill(_mqttWill, MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
if ((strlen(_mqttUser) > 0) && (strlen(_mqttPass) > 0)) { |
|
|
if ((strlen(_mqttUser) > 0) && (strlen(_mqttPass) > 0)) { |
|
|
DEBUG_MSG_P(PSTR(" as user '%s'."), _mqttUser); |
|
|
DEBUG_MSG_P(PSTR(" as user '%s'."), _mqttUser); |
|
|
mqtt.setCredentials(_mqttUser, _mqttPass); |
|
|
mqtt.setCredentials(_mqttUser, _mqttPass); |
|
@ -286,10 +288,10 @@ void mqttConnect() { |
|
|
|
|
|
|
|
|
if ((strlen(_mqttUser) > 0) && (strlen(_mqttPass) > 0)) { |
|
|
if ((strlen(_mqttUser) > 0) && (strlen(_mqttPass) > 0)) { |
|
|
DEBUG_MSG_P(PSTR(" as user '%s'\n"), _mqttUser); |
|
|
DEBUG_MSG_P(PSTR(" as user '%s'\n"), _mqttUser); |
|
|
response = mqtt.connect(getIdentifier().c_str(), _mqttUser, _mqttPass, will, MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
|
|
|
|
|
|
response = mqtt.connect(getIdentifier().c_str(), _mqttUser, _mqttPass, _mqttWill, MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
} else { |
|
|
} else { |
|
|
DEBUG_MSG_P(PSTR("\n")); |
|
|
DEBUG_MSG_P(PSTR("\n")); |
|
|
response = mqtt.connect(getIdentifier().c_str(), will, MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
|
|
|
|
|
|
response = mqtt.connect(getIdentifier().c_str(), _mqttWill, MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (response) { |
|
|
if (response) { |
|
@ -302,7 +304,6 @@ void mqttConnect() { |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
free(host); |
|
|
free(host); |
|
|
free(will); |
|
|
|
|
|
|
|
|
|
|
|
String mqttSetter = getSetting("mqttSetter", MQTT_USE_SETTER); |
|
|
String mqttSetter = getSetting("mqttSetter", MQTT_USE_SETTER); |
|
|
String mqttGetter = getSetting("mqttGetter", MQTT_USE_GETTER); |
|
|
String mqttGetter = getSetting("mqttGetter", MQTT_USE_GETTER); |
|
|