Skip to content

Commit

Permalink
Merge pull request #1757 from mcspr/mqtt/retry-states
Browse files Browse the repository at this point in the history
MQTT connection state
  • Loading branch information
xoseperez authored Jun 4, 2019
2 parents 79ee2a7 + 6452f17 commit c57a0ab
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions code/espurna/mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,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
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -363,6 +382,11 @@ void _mqttInitCommands() {
terminalOK();
});

terminalRegisterCommand(F("MQTT.INFO"), [](Embedis* e) {
_mqttInfo();
terminalOK();
});

}

#endif // TERMINAL_SUPPORT
Expand Down Expand Up @@ -405,6 +429,7 @@ void _mqttOnConnect() {
_mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;

_mqtt_last_connection = millis();
_mqtt_connecting = false;

// Clean subscriptions
mqttUnsubscribeRaw("#");
Expand Down Expand Up @@ -766,12 +791,7 @@ void mqttSetBrokerIfNone(IPAddress ip, unsigned int port) {
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

Expand Down

0 comments on commit c57a0ab

Please sign in to comment.