-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
nonblocking approach is indeed blocking #147
Comments
The point of the example is that it doesn't block the app the entire time the client is disconnected - so if it loses its network connection for 5 minutes, the sketch can continue running. But of course there is work involved in getting connected and that can take a little bit of time. The current API assumes connect returns true/false based on whether it got connected or not. If we changed it to be non-blocking, such that it would connect eventually, that would break a lot of sketches. An alternative would be to add an alternative connect function that wasn't blocking. But that isn't the quick solution you're looking for - I don't know when I'll get a chance to add such a function to the library. |
I see, I guess I will be very helpful! Am I right that only one chance to reduce the effect of the connection delay is to increase the time between the reconnections? |
Stumbled upon the same problem recently. I've used this library to send sensor values for quite some time now but now I've changed the sensor and its corresponding library. This one requires me to perform sensor readings within fixed deadlines (3 seconds). It works most of the time* but sometimes @knolleary do you think a timeout for * In fact I had a lot of connection drops actually and they are gone since I applied PR #472 |
Hello |
While not perfect, it's the best workaround for the blocking effects of the library that I've seen. Anything that makes my ESP8266 based animated LED displays stutter is immediately noticeable and this library has indeed been a killer if I lose connection to the broker. Connection, dis-connect and re-connect to wifi as well as the broker ALL need to be non-blocking. . . . The loop must flow. |
The solution shown by Spatnynick looks helpful. Are there things one can do to ensure the broker responds as fast as possible? The delay associated with MQTT reconnect messed up an application where I was trying to use rs485 to achieve control in an area where WiFi wasn't available. I wasn't successful in trying to control when the mqtt reconnect attempt happened in order to better control the rs485 side. |
For reference, #583 (comment) is the example by @spatnynick alluded to by @bobcroft above. |
I used example pubsubclient/examples/mqtt_reconnect_nonblocking/mqtt_reconnect_nonblocking.ino as base and added work with a button. Thus, If it calls
client.connect(...)
my script is unable to read button state in that moment. It's short period about 1-2s but it's weird. Is it possible to handle it in some way?There's example of important part of my app
https://gist.github.com/glebv/4b79298fc7ac23f342a42017cb77e6cd
The text was updated successfully, but these errors were encountered: