-
Notifications
You must be signed in to change notification settings - Fork 6.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
IoT: connection drop after around 24 hours #2603
Comments
Thanks for reporting this issue, I'll see if I can figure out what's going on. |
If i use the pubsub client library as also on your documentation this works flawlessly but then i get no information within the IoT console for things like last seen, heartbeat, config sent etc |
There are a lot of potential causes for a disconnect. If you go to the console and look up your device are you seeing any error details? |
I get either "The connection was closed or broken by the client" or i get "The authorization token expired" Which either doesnt make sense. The raspi is also hardwired to my router and im refreshing the token every 20 minutes. |
Or if i use the client library instead is there anyway to specify the device id so i can maintain status of each iot device? |
I'm able to reproduce the console error issue now. There's a chance the device is not correctly refreshing the JWT, but it looks like to me like it should work as the JWT is refreshed in the call to There's a chance on the reconnect we need to call: client.disconnect()
client.loop() To cleanly disconnect after this line to avoid the error. But I believe I have tested this before and it worked, despite the console errors. If you're doing a lot of calculations between the calls to |
ok i can update and try that. what is the difference between client.loop(), client.stop_loop() and client.loop_start() ? |
Don't mix |
Of note, adding the disconnect seems to be the right thing to do, I'm working on a PR to set it up. |
Also can evey ioT device use the same public key? Or should each device have a unique one? and does client.loop() can be called without calling client.loop_stop()? |
Ok so i added the disconnect here and i get this just repeating: Im using client.loop_start() every time the loop is entered as i get better performance with the async call. Should i be calling client.loop_stop() somewhere? If i just use client.loop() i see performance issues but it looks like the token refresh works but now my 30 second loop takes 60 seconds |
OK i think i figured it out. I kept with the async loop calls. I put a |
Sounds good, @kilabyte - I have created a new branch where we cleanly disconnect the MQTT sample. Feel free to reopen the issue if you're still seeing the client disconnecting or crashing. |
@gguuss can you just explain why you used .loop() and .loop_stop() in the same file? and i think for performance your PR would be better off with using the async calls instead that way you dont have to implicitly disconnect as i have found this has issues with the backoff in the disconnect callback |
@kilabyte Which file are you referring to? This should be a bug if it's going on. In my anecdotal tests, there is no harm in calling loop in the mix with loop_start() and loop_stop() but if you call loop_start without ever calling loop_stop later on, the program will hang. If you're referring to the removed lines from |
Gotcha! Thanks for the explanation :) much appreciated. For handling like network offline and disconnects that is where the backoff comes in right? And then any offline message that was "published" is stored locally until the network is back in which case the messages will all dump out? (sorry i know this is off topic to the issue) |
@kilabyte Yes, you got it. The back off is to ensure devices behave well under a number of circumstances. The sample/demo/example code itself does not buffer messages or do anything intelligent in terms of online / offline. There are other solutions built on top of Cloud IoT Core that are more robust. |
do you have links to said examples? |
A few come to mind: There's also the device SDK written in C. |
thank you! |
Our raspi connection to google iot via mqtt fails to persist past the 24hour mark. I have the JWT refreshing about every 20 mins or so.
Running on a raspi 3 with mqtt and code is identical from the examples posted here just changed my device id and project id and other vars to match my instance.
The text was updated successfully, but these errors were encountered: