umqtt: keepalive feature doesn’t function correctly
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- networking
Research direction
Start at the umqtt.simple MQTTClient implementation used by the example and trace how the keepalive argument is handled while wait_msg() blocks. Reproduce against Mosquitto or HiveMQ with keepalive=15; done means the client sends the required pings and remains connected beyond the broker timeout, with regression coverage for the behavior.
Written by the indexing model from the issue text.
Description
Hi!
Here’s some example code to reproduce the issue:
import ssl
import machine
import network
from umqtt.simple import MQTTClient
client_id = machine.unique_id().hex()
mqtt_server = 'XXX.s1.eu.hivemq.cloud'
mqtt_user = 'XXX'
mqtt_password = 'XXX'
mqtt_topic_sub = b'test/topic'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('XXX','XXX')
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
def mqtt_connect():
client = MQTTClient(client_id, mqtt_server, 8883, mqtt_user, mqtt_password, 15, ssl_context)
client.connect()
print('Connected to %s MQTT Broker'%(mqtt_server))
return client
def reconnect():
print('Failed to connect to the MQTT Broker. Reconnecting...')
machine.reset()
def callback(topic, msg):
print(topic, msg)
try:
client = mqtt_connect()
client.set_callback(callback)
client.subscribe(mqtt_topic_sub)
except OSError as e:
reconnect()
while True:
client.wait_msg()
The library allows setting the keepalive to any value (default is 0, which disables it). However, when you set a keepalive value, the library does not automatically send pings to the server as expected. This causes the server to disconnect the client after 1.5 times the specified keepalive duration.
Are there any possible solutions to this?
I tested this with Mosquitto and HiveMQ serverless.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.1k
- Avg merge
- 7d 4h
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from micropython/micropython-lib
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
micropython/micropython-lib#1074 ·
-
needs-info
Difficulty 1/5 Under an hour Newbie friendliness 72/100
micropython/micropython-lib#943 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
micropython/micropython-lib#931 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
micropython/micropython-lib#795 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
micropython/micropython-lib#762 ·
All issues in micropython/micropython-lib
Similar issues
-
bug confirmed issue
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
open-webui/open-webui#30750 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 90/100