← index #410Issue #112
Related · medium · value 0.785
QUERY · ISSUE

UMQTT - mqtt stops publishing after 5 minutes

openby TanCansopened 2021-01-27updated 2021-01-27

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:

umqtt.txt

Thank you all in advance!

CANDIDATE · ISSUE

Unconnected MQTT publish fails silently

closedby mkarlineropened 2016-10-30updated 2024-08-25

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....

5 comments
pfalcon · 2016-10-30

In fact, its a bit opaque to me how robust achieves its reconnection functionality.

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.

mkarliner · 2016-10-30

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?

pfalcon · 2016-10-30

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

mkarliner · 2016-10-30

Thanks for the explanation, obvious now you say.

jonnor · 2024-08-25

The question seems to have been resolved. Proposing to close.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied