|
@ -340,10 +340,10 @@ void mqttConnect() { |
|
|
char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str()); |
|
|
char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str()); |
|
|
if (strlen(host) == 0) return; |
|
|
if (strlen(host) == 0) return; |
|
|
unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt(); |
|
|
unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt(); |
|
|
_mqttUser = strdup(getSetting("mqttUser", MQTT_USER).c_str()); |
|
|
|
|
|
_mqttPass = strdup(getSetting("mqttPassword", MQTT_PASS).c_str()); |
|
|
|
|
|
if (_mqttWill) free(_mqttWill); |
|
|
|
|
|
_mqttWill = strdup((_mqttTopic + MQTT_TOPIC_STATUS).c_str()); |
|
|
|
|
|
|
|
|
_mqtt_user = strdup(getSetting("mqttUser", MQTT_USER).c_str()); |
|
|
|
|
|
_mqtt_pass = strdup(getSetting("mqttPassword", MQTT_PASS).c_str()); |
|
|
|
|
|
if (_mqtt_will) free(_mqtt_will); |
|
|
|
|
|
_mqtt_will = strdup((_mqtt_topic + MQTT_TOPIC_STATUS).c_str()); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[MQTT] Connecting to broker at %s:%d\n"), host, port); |
|
|
DEBUG_MSG_P(PSTR("[MQTT] Connecting to broker at %s:%d\n"), host, port); |
|
|
|
|
|
|
|
@ -393,7 +393,7 @@ void mqttConnect() { |
|
|
DEBUG_MSG_P(PSTR("[MQTT] Invalid fingerprint\n")); |
|
|
DEBUG_MSG_P(PSTR("[MQTT] Invalid fingerprint\n")); |
|
|
response = false; |
|
|
response = false; |
|
|
} |
|
|
} |
|
|
_mqttClientSecure.stop(); |
|
|
|
|
|
|
|
|
_mqtt_client_secure.stop(); |
|
|
yield(); |
|
|
yield(); |
|
|
} else { |
|
|
} else { |
|
|
DEBUG_MSG_P(PSTR("[MQTT] Wrong fingerprint\n")); |
|
|
DEBUG_MSG_P(PSTR("[MQTT] Wrong fingerprint\n")); |
|
@ -492,7 +492,7 @@ void mqttSetup() { |
|
|
|
|
|
|
|
|
#if MQTT_USE_ASYNC
|
|
|
#if MQTT_USE_ASYNC
|
|
|
|
|
|
|
|
|
mqtt.onConnect([](bool sessionPresent) { |
|
|
|
|
|
|
|
|
_mqtt.onConnect([](bool sessionPresent) { |
|
|
_mqttOnConnect(); |
|
|
_mqttOnConnect(); |
|
|
}); |
|
|
}); |
|
|
_mqtt.onDisconnect([](AsyncMqttClientDisconnectReason reason) { |
|
|
_mqtt.onDisconnect([](AsyncMqttClientDisconnectReason reason) { |
|
@ -549,7 +549,7 @@ void mqttLoop() { |
|
|
|
|
|
|
|
|
if (!_mqtt_enabled) return; |
|
|
if (!_mqtt_enabled) return; |
|
|
if (WiFi.status() != WL_CONNECTED) return; |
|
|
if (WiFi.status() != WL_CONNECTED) return; |
|
|
if (_mqtt.connected) return; |
|
|
|
|
|
|
|
|
if (_mqtt.connected()) return; |
|
|
|
|
|
|
|
|
static unsigned long last = 0; |
|
|
static unsigned long last = 0; |
|
|
if (millis() - last > MQTT_RECONNECT_DELAY) { |
|
|
if (millis() - last > MQTT_RECONNECT_DELAY) { |
|
|