MQTTClient erroring

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
rp346@njit.edu
Posts: 18
Joined: Sun Sep 16, 2018 6:33 pm

MQTTClient erroring

Post by rp346@njit.edu » Mon Nov 19, 2018 1:03 am

I am trying to connect to mqtt using umqtt.simple, here is my code

Code: Select all

from umqtt.simple import MQTTClient
SERVER_1 = "p44.cloudmqtt.com"
PORT_1 = 154321
USER_1 = b'user1'
PASSWORD_1 = b'0FVn7NrUPpd5'

DEVICE_ID = ubinascii.hexlify(machine.unique_id())

mqtt1 = MQTTClient(DEVICE_ID, SERVER_1, user=USER_1, password=PASSWORD_1, port=PORT_1)
mqtt1.connect()
Getting following error

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "umqtt/simple.py", line 99, in connect
MQTTException: 5
Any idea whats wrong here ?
- roy

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: MQTTClient erroring

Post by pythoncoder » Mon Nov 19, 2018 5:44 am

It would seem that the broker is is rejecting your connection credentials. When you connect it sends a 4 byte CONNACK packet. Bytes 0 and 1 must have been correct, otherwise the code would have thrown an assertion fail. However byte 3 must have had the value 5 for the code to throw that exception. Section 3.2.2.3 of the MQTT spec show that this bit pattern signifies "connection refused, identifier rejected", "The Client identifier is correct UTF-8 but not allowed by the server".
Peter Hinch
Index to my micropython libraries.

rp346@njit.edu
Posts: 18
Joined: Sun Sep 16, 2018 6:33 pm

Re: MQTTClient erroring

Post by rp346@njit.edu » Thu Nov 22, 2018 4:28 pm

Thanks
- roy

Post Reply