Open mrmay-dev opened 1 year ago
For the record, #142 proposes to use non-zero timeout for loop()
by default.
Going with #142 - leaving this open until #142 is resolved
This might be a bit old, but I got this issue on CP 9.1.2. Went through the code and it just didn't make any sense to use timeout > 0 for non-blocking loop ... in fact I tried but it would still block.
The solution for me was to patch adafruit_minimqtt.py and place self._sock.setblocking(False)
just after a new socket is created self._sock = self._connection_manager.get_socket(...)
(around line 494)
now the loop uses default timeout=0 (and socket_timeout=-1 in mqtt init) and it does not block anymore, hope this helps someone...
This happens with CircuitPython 7.3.3 and 8 beta-6 using the mpy-20221230 libraries for both 7 and 8 releases.
The
loop()
works flawlessly when run used with the AIO client. However, it stalls with plain MQTT.A simple workaround is to add a timeout (in seconds) to the loop:
mqtt_client.loop(timeout = 1)
I expect that while
loop()
is checking for updates the code below would send messages to the topic. What happens instead, is that theloop()
blocks the script until it receives a message and then it allows the rest of the code to run.To reproduce:
test/test-topic
while True
loop runs.To run the same loop with adafruit_io change the
use_MQTT = True
variable toFalse
.