dawidchyrzynski / arduino-home-assistant

ArduinoHA allows to integrate an Arduino/ESP based device with Home Assistant using MQTT.
https://dawidchyrzynski.github.io/arduino-home-assistant/
GNU Affero General Public License v3.0
498 stars 118 forks source link

Mqtt.loop blocking #140

Closed PM04290 closed 8 months ago

PM04290 commented 1 year ago

If no mqtt server available, or wifi/ethernet fail, mqtt.loop() freeze the main loop during many seconds. is it possible to modify process of mqtt.loop with non blocking ? something like true/false return. i must fork this library to solve problem and it's not a good solution for future.

are you knowing "async-mqtt-client" library ? is it possible to choose this one or PubSubClient ?

xardas689 commented 1 year ago

The async-mqtt-client library is only working on esp devices. This library is designed to work with avr based processors as well and therfore using the PubSubClient internally with a wrapper build on top of it.

Besides that: I am not able to reproduce the error on an arduino mega board. But i noticed that the wrapper is calling the underlying loop function directly. It may help if you use the nonblocking reconnection.

rikki78 commented 1 year ago

the nonblocking reconnection still will block the loop, as it waits 15s until it gets connected. If you want to avoid this you have to run the entire mqtt.loop(); in a different ESP task than the program loop

dawidchyrzynski commented 8 months ago

Duplicate of #77