In case of an external WiFi disconnect event, the device does not reconnect (loop() does not contain any logic for verifying and re-establishing a terminated WiFi connection), which causes an MQTT disconnect as well. However, in such an event, the device tries to reconnect to MQTT broker (without being connected to WiFi), which causes an endless loop in MQTT_connect().
In case of an external WiFi disconnect event, the device does not reconnect (
loop()
does not contain any logic for verifying and re-establishing a terminated WiFi connection), which causes an MQTT disconnect as well. However, in such an event, the device tries to reconnect to MQTT broker (without being connected to WiFi), which causes an endless loop inMQTT_connect()
.