The whole Homie for ESP8266 code is designed to be non-blocking, so that you can do other tasks in the main loop(). However, the connection to the MQTT broker is blocking during ~5 seconds in case the server is unreachable. This is an Arduino for ESP8266 limitation, and we can't do anything on our side to solve this issue, not even a timeout.
This is not really true, it is possible to avoid connecting / reconnecting to the MQTT if a critical operation is happening. Let's say you are controlling shutters with a relay, you want your loop to be executed without the 5 seconds delay mentionned above, because else you will loose the current state of your shutters. Before moving the shutters, you could do:
Homie.enableSafeMode(true);
If the MQTT connection is lost while in safe mode, it does not try to reconnect. When the shutters is done moving, we call back:
Homie.enableSafeMode(false);
It would then reconnect if previously disconnected.
There is a limitation, from the Wiki
This is not really true, it is possible to avoid connecting / reconnecting to the MQTT if a critical operation is happening. Let's say you are controlling shutters with a relay, you want your loop to be executed without the 5 seconds delay mentionned above, because else you will loose the current state of your shutters. Before moving the shutters, you could do:
If the MQTT connection is lost while in safe mode, it does not try to reconnect. When the shutters is done moving, we call back:
It would then reconnect if previously disconnected.