pycom / pycom-libraries

MicroPython libraries and examples that work out of the box on Pycom's IoT modules
330 stars 379 forks source link

mqtt.connect() fails if remaining length exceeds 128 #130

Open superkartoffel opened 3 years ago

superkartoffel commented 3 years ago

What are the steps to reproduce this issue?

  1. Connect to any mqtt broker using mqtt.py with values for username, clientId, password and/or will-message so that the "remaining length" of the connect message exceeds 128, i.e.:
    client = MQTTClient("d5dab9db471a417f95c1e86d61b8b68e", "mqtt.eclipse.org", port=1883, user="d5dab9db471a417f95c1e86d61b8b68e", password="d5dab9db471a417f95c1e86d61b8b68e", keepalive=60)
    client.set_last_will(topic="some/d5dab9db471a417f95c1e86d61b8b68e/topic", msg="d5dab9db471a417f95c1e86d61b8b68e")
    client.connect()

What happens?

The broker will reset the connection after receiving the CONNECT packet.

What were you expecting to happen?

The broker should not reset the connection.

Any logs, error output, etc?

Unfortunately no. After reading the code and the mqtt specification, I found out, that mqtt.py does not implement the "remaining length" field correctly for values above 128. See mqtt 3.1.1 specification

Any other comments?

The publish packet seems to implement this field correctly.