UMQTT - mqtt stops publishing after 5 minutes
Hello everyone,
i am using umqtt library to publish some telemetry data to an IoT platform with a pycom microcontroller. But mqtt stops publishing data exact after five minutes even though it is still connected to wlan.
I am sharing the piece of code that calls mqtt client and the library
Connecting wlan:
wlan.connect('my wlan', auth=(None,'my password'), timeout= 50000) #even though i changed this timeout it didnt solve my problem
My credentials (for iot platform)
server = 'my server'
port = 1883
id = 'my id'
pw = ‘acces token’
topic_publish = 'v1/devices/me/telemetry'
dict={}
Creating a client:
Client = MQTTClient(id, server, port, pw, pw)
time.sleep(2)
client.connect()
Publishing in the loop:
While 1
encoded=ujson.dumps(dict)
client.publish(topic_publish, encoded)
time.sleep(1)
Umqtt library:
Thank you all in advance!
Unconnected MQTT publish fails silently
If I connect up an MQTT client and publish (sucessfully), then stop the broker, subsequent publishes fail without error. I'm not sure if this is the desired functionality or not. In fact, its a bit opaque to me how robust achieves its reconnection functionality.
connected with mihome, channel 6
dhcp client start...
ip:192.168.10.185,mask:255.255.255.0,gw:192.168.10.1
from simple import MQTTClient
c = MQTTClient("adcdd", "192.168.10.195") # Broker not running
c.connect()
0
c.publish("foo", "Hello MQTT")
..# Stop broker
c.publish("foo", "Hello MQTT")No exception....
It doesn't have to be like that - code is at every MicroPython user's fingertips and simple to understand: https://github.com/micropython/micropython-lib/blob/master/umqtt.robust/umqtt/robust.py#L29
I'll look into the main topic of this issue when time permits.
Sorry, me being unclear. Looking at the code, I wonder how robust would reconnect in a situation other than a publish failure, ie: loss of connection with subscribe only?
Subscription requires running event loop (wait_msg() function). It's also protected in a similar fashion to publish(): https://github.com/micropython/micropython-lib/blob/master/umqtt.robust/umqtt/robust.py#L37
Thanks for the explanation, obvious now you say.
The question seems to have been resolved. Proposing to close.