From 5ca44c1c4cbddb94661337508f34cf2e7eba989a Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Wed, 15 May 2019 17:08:00 +0300 Subject: [PATCH 1/2] mqtt: display connection state, mqtt.info command --- code/espurna/mqtt.ino | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index e4db050f..73767919 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -267,6 +267,25 @@ void _mqttBackwards() { } } +void _mqttInfo() { + DEBUG_MSG_P(PSTR("[MQTT] Async %s, SSL %s, Autoconnect %s\n"), + MQTT_USE_ASYNC ? "ENABLED" : "DISABLED", + ASYNC_TCP_SSL_ENABLED ? "ENABLED" : "DISABLED", + MQTT_AUTOCONNECT ? "ENABLED" : "DISABLED" + ); + DEBUG_MSG_P(PSTR("[MQTT] Client %s, %s\n"), + _mqtt_enabled ? "ENABLED" : "DISABLED", + _mqtt.connected() ? "CONNECTED" : "DISCONNECTED" + ); + DEBUG_MSG_P(PSTR("[MQTT] Retry %s (Now %u, Last %u, Delay %u, Step %u)\n"), + _mqtt_connecting ? "CONNECTING" : "WAITING", + millis(), + _mqtt_last_connection, + _mqtt_reconnect_delay, + MQTT_RECONNECT_DELAY_STEP + ); +} + // ----------------------------------------------------------------------------- // WEB // ----------------------------------------------------------------------------- @@ -314,6 +333,11 @@ void _mqttInitCommands() { terminalOK(); }); + terminalRegisterCommand(F("MQTT.INFO"), [](Embedis* e) { + _mqttInfo(); + terminalOK(); + }); + } #endif // TERMINAL_SUPPORT @@ -729,12 +753,7 @@ void mqttReset() { void mqttSetup() { _mqttBackwards(); - - DEBUG_MSG_P(PSTR("[MQTT] Async %s, SSL %s, Autoconnect %s\n"), - MQTT_USE_ASYNC ? "ENABLED" : "DISABLED", - ASYNC_TCP_SSL_ENABLED ? "ENABLED" : "DISABLED", - MQTT_AUTOCONNECT ? "ENABLED" : "DISABLED" - ); + _mqttInfo(); #if MQTT_USE_ASYNC From 6452f1777ec43ec4835abb007900e092c577cdfb Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Wed, 15 May 2019 17:33:02 +0300 Subject: [PATCH 2/2] mqtt: remove 'connecting' flag when connected --- code/espurna/mqtt.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index 73767919..d97422ca 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -380,6 +380,7 @@ void _mqttOnConnect() { _mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN; _mqtt_last_connection = millis(); + _mqtt_connecting = false; // Clean subscriptions mqttUnsubscribeRaw("#");