|
@ -208,6 +208,7 @@ 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()); |
|
|
|
|
|
|
|
|
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); |
|
@ -215,7 +216,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((mqttTopic + MQTT_TOPIC_STATUS).c_str(), MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
|
|
|
|
|
|
mqtt.setWill(will, 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); |
|
@ -229,10 +230,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, (mqttTopic + MQTT_TOPIC_STATUS).c_str(), MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
|
|
|
|
|
|
response = mqtt.connect(getIdentifier().c_str(), _mqttUser, _mqttPass, will, MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
} else { |
|
|
} else { |
|
|
DEBUG_MSG_P(PSTR("\n")); |
|
|
DEBUG_MSG_P(PSTR("\n")); |
|
|
response = mqtt.connect(getIdentifier().c_str(), (mqttTopic + MQTT_TOPIC_STATUS).c_str(), MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
|
|
|
|
|
|
response = mqtt.connect(getIdentifier().c_str(), will, MQTT_QOS, MQTT_RETAIN, "0"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (response) { |
|
|
if (response) { |
|
@ -245,6 +246,7 @@ 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); |
|
|