Hello Nick !
I am using your code " Starter for a MQTT integration using Python3" (thanks much !) and I have some trouble with the Subscribe Uplink code. As you know the last lines of the code are:
try:
run = True
while run:
mqttc.loop(10) # seconds timeout / blocking time
print(".", end="", flush=True) # feedback to the user that something is actually happening
except KeyboardInterrupt:
stop(mqttc)
Everything works fine except that from time to time, once every 2-3 days, the code prints “.” at fast pace but doesn’t do anything else while the code on my node continues to send uplinks. I have to stop the python program receiving uplinks and relaunch it.
Any idea on what could be wrong in my set-up ?
My node sends an uplink once per minute (for test reasons, it will be less once in operation) 24/7. I tried to reduce to one uplink every 5mn and still had the same issue.
Thanks much !
-Henri
I’ve moved this out of a PM so others can contribute as well as me. Free private consultations won’t keep my cats in Felix Doubly Delicious Country Meat as well as Dreamies.
On the face of it there must be a memory leak somewhere in the Paho library that accumulates as we show the keep alive on the terminal. I put it in so that those getting started could see that something was actually happening - particularly important when you only have one or two devices.
For real there’s usually enough traffic to have it show something every minute so no keep alive tick is required.
But as it’s a starter library, I’d rather it work as intended, so I’ll have a look.
In the meanwhile, you could change:
run = True
while run:
mqttc.loop(10) # seconds timeout / blocking time
print(".", end="", flush=True) # feedback to the user that something is actually happening
to:
mqttc.loop_forever()
Which will require some very serious Ctl-C’ing to get the attention of the Python interpreter if you want to exit, I usually end up killing the process. Another reason it’s coded the way it is.