Mqtt refusing connection

So I am struggling to get MQTT working on my local instance. I have followed several directions, and I think I have it set up, but I still can not get any connections.
I can go to integrations > MQTT > Configure, and I can publish and listen without any issues. However, if I try to publish on anything else such as the terminal I am constantly getting connection refused. It is a combination of “Connection Refused”, “Unable to connect (Lookup error.)” and “Connection refused: not authorized”. I get the different errors based on how I am trying to publish.

Inside the logs, this is the only message that I get “error: received null username or password for unpwd check
1657070553: Client disconnected, not authorised.”

Earlier in the day, I did set up my system and network for port-forwarding and am using Duck DNS. This does work as expected. I am at a loss as to what simple thing I am overlooking here and would appreciate any help.

Paul

Which broker are you using?

Why are you trying to publish from the terminal?

Are you including the user credentials when publishing from the terminal?

Thanks for the quick response tom. I am using the Mosquitto broker. My end game is to get hass agent up and running with MQTT which is not connecting, so I was trying to see if I could publish messages or if it is a different issue. I am not including user credentials when I tried to send from the terminal.

EDIT
just a few more minutes and I was able to get it figured out. What I had to do was supply the local IP of HA instead of using my external duckdns address.

That’s your problem.

Home assistant creates a system user for the mqtt integration and Mosquitto addon in the background and can connect using this. It is why you can’t use the usernames homeassistant or addons. From the addon documentation:

You have two options.

  1. create a user in home assistant (the addon can look this up), or
  2. create a local user in the addon configuration.

e.g.

logins:
  - username: mqtt_user
    password: my_super_strong_password_34

Supply these user credentials for any device (or terminal) you want to connect to the broker.

FYI the MQTT Explorer program that runs on any PC is excellent for checking on what is going on in your broker.

1 Like

@tom_l tom_l

Thanks for this info Tom, Im having similar credential problems with Mosquitto broker:

Since last nite all my Insteon devices have become unavailable in HA. They work from Alexa or thru the App only.

Im running HAOS on a windows VM. I restarted the host box, and the Insteon Hub. No change - Could not connect to Insteon modem. I restarted MQTT. The hub is up on the same IP, but HA cant connect.

This is happening with other new devices I added last nite as well:

I do have a local mqtt user setup, which was all working fine until last nite. Would an easy fix be to

" enable unrestricted access to all topics for [YOUR_MQTT_USER] ." ?

Thanks much for any info, you helped me so much when I first installed HA last month, really apprciate it. Im gonna check out MQTT Explorer right now.

I don’t know anything about the insteon integration. So I’m going to assume the integration connects via mqtt to the hub. If that is wrong, ignore this:

It looks like your Insteon hub has lost the mqtt user credentials. Can you check them?

No because no username or password is being supplied to the broker.

See “null username or password” highlighted in blue in your first image.

Actually that could also be the insteon integration. Did you have to supply the mqtt broker credentials when you set the insteon integration up?

If so, check that setting too.

Thanks for the input Tom :+1:

I’m going to assume the integration connects via mqtt to the hub.

Yes Im pretty sure thats the case.
I see some others with similar issues here:

Still not sure if this is Insteon hub or mqtt, VM networking, SSL, or integration issue. :thinking:
I’ll drop a post over there as well. I’ll also load up MQTT Explorer

Thank you Tom!

It does not look like a network issue. The hub or integration can reach the broker and connect. It is just not supplying a username or password.

The good news is, tried pinging the insteon hub and got nothing. Network scan showed it got a new IP. I re-run configure on the insteon integration with the new IP and all the devices came back :sweat_smile:

The bad news is… all the same / Fresh errors in the Mosquitto broker logs persist

Mosquitto broker

1658211220: New connection from 172.30.32.1:52686 on port 1883. error: received null username or password for unpwd check 1658211220: Client disconnected, not authorised. 1658211225: New connection from 172.30.32.1:52700 on port 1883. error: received null username or password for unpwd check 1658211225: Client disconnected, not authorised. 1658211230: New connection from 172.30.32.1:43438 on port 1883. error: received null username or password for unpwd check 1658211230: Client disconnected, not authorised. 1658211235: New connection from 172.30.32.1:43444 on port 1883. error: received null username or password for unpwd check 1658211235: Client disconnected, not authorised. 1658211240: New connection from 172.30.32.1:54794 on port 1883.

At least im back up and running for now, I’ll save this error hunt for another day. Im sure the explorer app will reveal it. If there’s anything the dev’s can do to accomodate devices/hubs changing IP’s that would be really great for us newbies. Thanks again tom!

I’ve got similag problem today. Issue solved when I chechek mqtt object configuration witihn inegrations. There is option where you need to set system user for mqtt server.

Had a similar problem today, and solved it by changing the usernames to all lowercase letters, both Broker and User account, had the problem.

In the log there is also mentioned something about the auth provider running in legacy mode, might have somthing to do with it, as it was flawless before this.

1 Like

After changing the username that was reported by Auth Provider using:

https://community.home-assistant.io/t/how-to-change-a-username/79362/4

All login problems i had disappeared.

Just in case anyone comes across this later from a Google search, the Mosquitto Broker add-on no longer supports anonymous MQTT connections, as clarified here: https://github.com/home-assistant/addons/issues/2623#issuecomment-1222390957

1 Like