diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index 23b3e458..33a6ad2a 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -139,8 +139,7 @@ void mqttConnect() { if (!mqtt.connected()) { - char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str()); - if (strlen(host) == 0) return; + if (getSetting("mqttServer", MQTT_SERVER).length() == 0) return; // Last option: reconnect to wifi after MQTT_MAX_TRIES attemps in a row #if MQTT_MAX_TRIES > 0 @@ -161,6 +160,7 @@ void mqttConnect() { mqtt.disconnect(); + char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str()); unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt(); char * user = strdup(getSetting("mqttUser").c_str()); char * pass = strdup(getSetting("mqttPassword").c_str()); @@ -176,6 +176,10 @@ void mqttConnect() { DEBUG_MSG("\n"); mqtt.connect(); + free(host); + free(user); + free(pass); + } }