MQTT – User name and password authentication to MQTT Broker connection


MQTT clients can connect to MQTT Broker through an anonymous connection without any user authentication. Public MQTT brokers such as Eclipse MQTT Brokey allows user to connect to their server anonymously.

MQTT Brokers support user authentication through username and password. You can configure user authentication in Mosquitto MQTT broker. When user authentication is enabled, a valid user name and password is required for connection.

Related Topics

Using the AT Command Tester tool, you can test MQTT Broker connection both anonymously and with username and password.

MQTT Connection – Username and Password

Below server log shows an successful connection when the MQTT client passes a valid username and password.
C:\Program Files\mosquitto>mosquitto -v -c mosquitto.conf
1557294818: mosquitto version 1.6.0 starting
1557294818: Config loaded from mosquitto.conf.
1557294818: Opening ipv6 listen socket on port 1883.
1557294818: Opening ipv4 listen socket on port 1883.
1557294846: New connection from 127.0.0.1 on port 1883.
1557294846: New client connected from 127.0.0.1 as 8097 (p2, c1, k60, u’john’).
1557294846: No will message specified.
1557294846: Sending CONNACK to 8097 (0, 0)

Below MQTT server log shows connection failure because the username and password provided by the MQTT client cannot be authenticated.

1557294870: New connection from 127.0.0.1 on port 1883.
1557294870: Sending CONNACK to 127.0.0.1 (0, 5)
1557294870: Socket error on client <unknown>, disconnecting.
1557294870: New connection from 127.0.0.1 on port 1883.
1557294871: Sending CONNACK to 127.0.0.1 (0, 5)
1557294871: Socket error on client <unknown>, disconnecting.

Keywords: Module , M2M , GPRS , 3G , through AT commands,