mqtt DISCONNECTED log fix
This commit is contained in:
parent
9f4f0dba79
commit
d8eb6c87d8
@ -32,14 +32,15 @@ void mqttSetup() {
|
|||||||
|
|
||||||
void mqttDisconnect() {
|
void mqttDisconnect() {
|
||||||
if (mqttConnected) {
|
if (mqttConnected) {
|
||||||
error("MQTT", "Disconnecting...");
|
info("MQTT", "Disconnecting");
|
||||||
mqtt.disconnect();
|
mqtt.disconnect();
|
||||||
|
mqttConnected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqttLoop() {
|
void mqttLoop() {
|
||||||
const bool connected = mqtt.loop();
|
const bool connected = mqtt.loop();
|
||||||
if (mqttConnected != !connected) {
|
if (mqttConnected != connected) {
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
error("MQTT", "DISCONNECTED");
|
error("MQTT", "DISCONNECTED");
|
||||||
}
|
}
|
||||||
@ -47,7 +48,7 @@ void mqttLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isWiFiConnected() && isTimeSet() && !connected && (mqttLastConnectTry == 0 || millis() - mqttLastConnectTry > CONNECT_TIMEOUT_MILLISECONDS)) {
|
if (isWiFiConnected() && isTimeSet() && !connected && (mqttLastConnectTry == 0 || millis() - mqttLastConnectTry > CONNECT_TIMEOUT_MILLISECONDS)) {
|
||||||
error("MQTT", "Connecting: \"%s\"", MQTT_HOST);
|
error("MQTT", "Connecting MQTT host: %s", MQTT_HOST);
|
||||||
mqttLastConnectTry = millis();
|
mqttLastConnectTry = millis();
|
||||||
mqtt.setServer(MQTT_HOST, 1883);
|
mqtt.setServer(MQTT_HOST, 1883);
|
||||||
if (!mqtt.connect(HOSTNAME, logTopic, 0, false, "MQTT disconnected")) {
|
if (!mqtt.connect(HOSTNAME, logTopic, 0, false, "MQTT disconnected")) {
|
||||||
|
|||||||
@ -148,7 +148,7 @@ void wifiLoop() {
|
|||||||
} else {
|
} else {
|
||||||
if (hasIp) {
|
if (hasIp) {
|
||||||
wifiConnected = true;
|
wifiConnected = true;
|
||||||
info("WIFI", "Connected: ip=%s", WiFi.localIP().toString().c_str());
|
info("WIFI", "WiFi connected: ip=%s", WiFi.localIP().toString().c_str());
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
configTime(TIMEZONE_OFFSET, DST_OFFSET, WiFi.gatewayIP().toString().c_str(), NTP_SERVER);
|
configTime(TIMEZONE_OFFSET, DST_OFFSET, WiFi.gatewayIP().toString().c_str(), NTP_SERVER);
|
||||||
} else if (millis() - wifiLastConnectTry > WIFI_TIMEOUT_MS) {
|
} else if (millis() - wifiLastConnectTry > WIFI_TIMEOUT_MS) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user