micropython-mqtt: "Bad CONNACK" when connecting to HiveMQ broker

I am trying to connect to a free broker from HiveMQ. Everything works fine when I use the following config on a public test broker (from eclipse)

config["client_id"] = "uPy-client-004"
config["port"] = 8883
config["ssl"] = True
# # Eclipse config
# config["server"] = "mqtt.eclipseprojects.io"
# config["user"] = "rw"
# config["password"] = "readwrite"

However, when I switch the server, user, and password to the appropriate values for my HiveMQ broker, I receive the “BAD CONNACK” error.

This exact config (server, port, user, pass, etc) work successfully in other clients, including the simple umqtt included in micropython-lib.

It appears to be caused by this clause in the _connect method:

if resp[3] != 0 or resp[0] != 0x20 or resp[1] != 0x02:
            raise OSError(-1, "Bad CONNACK")  # Bad CONNACK e.g. authentication fail.

This is the value of resp when connecting to Eclipse (working config): bytearray(b' \x02\x00\x00')

This is the value of resp when connecting to HiveMQ (not working): bytearray(b' \x02\x00\x05')

I’ve been trying figure out what that 4th byte in the response means, beyond indicating that the authentication was unsuccessful.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

I’m always open to suggestions, but please check out my latest version of the readme as I updated it late yesterday.

I’d rather not change the code of the TLS samples as these have been tested, but code comments would be welcome.