Mosquitto add-on: Connection refused

Another thing I found useful, when I wasn’t sure if my Sonoff devices were connecting successfully, was to use the mosquitto_sub command line tool to subscribe to the top level of the topic tree with the # wildcard - you can then see all the messages coming in. It looks something like this:

$ mosquitto_sub -h 192.168.0.31 -u hassio-mqtt -P xyxyx -t '#' -v

My username is hassio-mqtt and xyxyx represents the password, and of course you need to substitute the IP address of your MQTT broker, which is generally your hassio machine. (I was running on another machine so I needed to add it with the -h option).

Depending on your version of the client software, you might also need to specify a client id with -I my_client_name before the broker will accept the connection.

In my case a new message appears about once a minute.

1 Like

https://imgur.com/a/KXqTENj Is this right?

This is my add-on logs. It seems like it works, isn’t it?

1550231642: New connection from my-pi-ip-address on port 1883.
[INFO] found my-user on Home Assistant
1550231644: New client connected from my-pi-ip-address as mosqsub|2023-a0d7b954-s (c1, k60, u'my-user').
1 Like

Yes, that looks right - do you get any messages from it? You can also open another window and try publishing some to the broker yourself - e.g.

mosquitto_pub -h 192.168.0.31 -u hassio-mqtt -P xyxyx -t testtopic -m "Hello"

You should see something appear in the output of your mosquitto_sub command.

If that works, then the broker is definitely working. If other things are failing to connect and send messages, then it may be an authentication issue, or it may be that you can connect from your local machine but not from elsewhere (e.g. if the devices are on a different subnet, or you have a firewall installed…).

Also, what do you have that’s trying to connect to the broker? Does it give you any output?

It’s just like deja vu, isn’t it? :wink::smile:

1 Like

You’re not wrong…

1 Like

I’ve finally could see a received message after enabling debugging in SSH. MQTT finally works for me. Thanks all for your help!

For any future visitors, if you are trying to communicate from another computer/client I had to create another user for my client in this case mosquitto_pub