-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
minimqtt blocking on .loop() method #148
Comments
This may be due to library issues in the Wiznet or the MQTT libraries. I'm going to move this to the MQTT library for now. Do you see the same thing if you use WiFi (on another board, obviously)? |
Observed the same issue on my board. Additionally, if no messages are published for a while the following error is received.
I found another reference to a similar issue #70
I tried to force the library to use the implementation under else with the following code in my main file:
But setting the attribute to either True or False doesn't seem to affect anything. The if block is always executed. |
Seeing this same issue, my projects gets to the loop and then stalls. Setting a timeout doesn't help. |
I've come across what I believe is the same issue on PyPortal but only get a MMQTTException error if I specify a timeout. With the default timeout the loop blocks. |
Same issue here on the Metro M4 airlift. loop is blocking and hence no further code is being executed for ~11 seconds while the M4 constantly receives new MQTT messages. Is there some workaround for this issue or is someone actively investigating this? |
I found myself confused about all of this too, and at least to me I think the various timeouts are confusing at best; for both types of sockets in Adafruit_CircuitPython_MiniMQTT/adafruit_minimqtt/adafruit_minimqtt.py Lines 1118 to 1126 in 9d4615b
When I set Some overall clarity on whether any of this is the intended functionality would help! |
Also seeing this with the PyPortal Titano |
I believe I found the underlying problem for ESP32SPI users (I'm using a PyPortal). It is documented in #165. My ESP32SPI workaround is documented there as well. |
I have a similar issue on "Adafruit CircuitPython 8.2.0 on 2023-07-05; Raspberry Pi Pico W with rp2040". I was able to change the duration of the time blocked by changing socket_timeout. As socket_timeout has a minimum/default value of 1 second it really messes up the LED fade timings in my project. This will show "Looped" every 5 seconds.
|
I am running into a similar issue on the Feather M4 Express on 8.2.4 -- having inspected the code I am not 100% sure how this is supposed to engage with the loop(timeout=0) timeout field. I think that the problem is that the timeout functionality of I can't actually test a fix because I don't know how to compile the python code into the .pym files, but I would expect that the The workaround that we have is to shorten |
@adsherman09 it should be possible to test / develop without compiling code to .mpy format. plain text .py files should also work and execute just fine on the microcontroller. The mpy compilation step is used just to save extra space, but it's not a requirement for code to execute, the plain text python code can run as well. Make sure that you are using the latest ESP32SPI library (if you are using an ESP32SPI "Airlift" based device), as the latest release of that does contain changes that could be relevant to the blocking loop issue. I was thinking that when I last tested this with the latest version of that library that there was no more blocking issue occurring. But I tested many variations of different things around that time, perhaps I'm mis-remembering the outcome. If you've tried with latest versions of the libraries and are up for poking around the code and potentially submitting a PR with the fix that you've outlined, that would be much appreciated. Submitting the PR also does not require compiling to .mpy format, only plain text python code is checked in to the repo. We have an automated actions task that does the mpy compilation whenever a new release is made, so it's not something that is typically done manually. |
@FoamyGuy thanks, we tested it. Realized after the fact that the mpy files that we were digging in were in the WizNet5k library anyway, and that this was in py format 🤦. I added the timeout argument to the places where I thought it would matter, and while it functioned as expected, we were surprised to find that publishing still took something like 2 seconds even with timeout=0 (aka single pass). The whole time the device was blocked so we couldn't even continue to take readings alongside to send in cached format. We're using a Feather M4 + Ethernet Featherwing -- I am honestly not sure if that is an ESP32SPI "Airlift" device, but I believe it is not. I don't want to submit a PR because I am not confident that my changes wont break other things! Update: I found the source of our additional hidden delays, and in order to utilize this function correctly the I have attached my adjusted code in lieu of a PR, you can find my adjustments in line 1007, the method definitions of |
I notice the adafruit-circuitpython-bundle-py-20230307 version of the minimqtt library does not have this problem with the loop method. |
That version of the file definitely has some more timeout propagation, it passes the loop timeout to _wait_for_msg and then calls |
Just hit this myself |
Not to pile on, but seeing this exactly on a Feather 2040 running. Without loop, as long as I send something more often than ever 60 seconds, it works, which is fine, I am sending some sensor data more often than that. But I can't receive anything right now which I would like to do. None of the timeout= and socket_timeout= attempts listed above helped.
bundle 20231220 |
Looks like there is a PR fix by @rjauquet! Who can review and approve? |
wow, cant wait, been fighting this for some time. |
where can you see this? |
You can find it at PR184. Waiting on someone with merge rights to merge it. |
CircuitPython version
Code/REPL
Behavior
I'm having some problems with MQTT with circuitpython.
I'm using circuitpython on a W5500-EVB-Pico board to read data from GPIO inputs and then publish that data using MQTT.
I notice that my call to g_mqtt_client.loop() is blocking.
If however I publish a message on the topic "HELLO/WORLD", sometimes the loop() method unblocks and continues until it reaches the loop() method again. If I set the timeout parameter on the loop() method to 1, this doesn't change anything.
Description
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: