MQTT thing offline - Connection refused

Hi,
I have openhabian on my raspberry PI4. I have the MQTT Thing offline. I install MOSQUITTO via the openhabian-config tool.
If I choose no password the system works. If I set a password don’t works.

This is without password:

and this with password.

2022-10-28 20:20:46.912 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:broker:f2be3ff7f8' changed from OFFLINE (COMMUNICATION_ERROR): io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /192.168.178.35:8883 to OFFLINE

2022-10-28 20:20:46.924 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:broker:f2be3ff7f8' changed from OFFLINE to OFFLINE (COMMUNICATION_ERROR): io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /192.168.178.35:8883

I want to avoid to use the MQTT without the password. I read all the other 21 posts with similar problrem in the comunity but unfortunally I didn’t find the solution. I tryed to reinstall mosquitto, chenge use, reset password, try different password, reboot the raspebby.

Any idea please?

Thank you and regards.
Alfonso

Did you click “Show advanced” and then enter your username and password?

image

From what you’ve said and the screenshots you posted, it sounds like you just toggled the “Secure Connection” switch.

Yes, of course I set the username and the password but still don’t work.

Sorry if that came across rudely, as I didn’t mean for that to be the case. There have been times when I’ve assumed someone has done something, and it turns out that they missed it. I’ve also been guilty of overlooking something simple steps. So when it’s not directly stated, it’s always worth asking the question. What’s obvious to you and me may not be obvious to someone else.

I would try using MQTT Explorer to connect to the broker with the password set up. That will at least tell you that the broker/password is working properly.

You use port 8883 instead of port 1883 because you would like to use encrypted connection ?
What does the mosquitto.log in /var/log/mosquitto show ? Any verbose error message that helps to identify the root cause ?

I think yes that 8883 is the port for use encripted connection.

@rpwong with MQTT explorer I think is the same…without password works and with password no.
I put also the last row of the log… I don’t know if is normal or not…


1666980929: mosquitto version 2.0.11 terminating
1666980929: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1666980929: mosquitto version 2.0.11 starting
1666980929: Config loaded from /etc/mosquitto/mosquitto.conf.
1666980929: Opening ipv4 listen socket on port 1883.
1666980929: Opening ipv6 listen socket on port 1883.
1666980929: mosquitto version 2.0.11 running
1666981345: New connection from 192.168.178.35:54254 on port 1883.
1666981345: New client connected from 192.168.178.35:54254 as 093ff4cb-9068-49ba-93c3-4a24083878ba (p2, c1, k60).
1666982730: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1666984531: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1666985478: New connection from 192.168.178.27:47220 on port 1883.
1666985478: Client <unknown> disconnected, not authorised.
1666985505: New connection from 192.168.178.27:36112 on port 1883.
1666985505: Client <unknown> disconnected, not authorised.
1666985508: New connection from 192.168.178.27:36126 on port 1883.
1666985508: Client <unknown> disconnected, not authorised.
1666985514: New connection from 192.168.178.27:48628 on port 1883.
1666985514: Client <unknown> disconnected, not authorised.
1666985546: New connection from 192.168.178.27:47114 on port 1883.
1666985546: Client <unknown> disconnected, not authorised.
1666985550: New connection from 192.168.178.27:47118 on port 1883.
1666985550: New client connected from 192.168.178.27:47118 as mqtt-explorer-ad41685d (p2, c1, k60).
1666985612: Client mqtt-explorer-ad41685d disconnected.
1666985636: New connection from 192.168.178.27:53102 on port 1883.
1666985636: New client connected from 192.168.178.27:53102 as mqtt-explorer-ad41685d (p2, c1, k60).
1666985643: Client mqtt-explorer-ad41685d disconnected.
1666985712: Client 093ff4cb-9068-49ba-93c3-4a24083878ba disconnected.

Would this mean that encryption needs to be toggled on? I don’t know much about ports or encryption with Mosquitto.

image

@fonzies83, what happens if you use 1883?

Looking to the log file it looks like your instance listens on port 1883 only.
mosquitto config needs to be changed to listen on 8883.

To check you may run

sudo nestat -tulpn |grep mosquitto

@rpwong so…something change :grinning:
With MQTT explore if I choose this settings works and the connection starts only if I put the correct password:

In openHab works but also without password…I think is not safetry right :roll_eyes:

@Wolfgang_S

penhabian@openhabian:/var/log/mosquitto $ sudo netstat -tulpn |grep mosquitto
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      7550/mosquitto      
tcp6       0      0 :::1883                 :::*                    LISTEN      7550/mosquitto      

Yes, as stated mosquitto is not configured to use encryption.
You may have a look at OHAB 3.2.0 cannot get MQTT working with SSL

Does your mosquitto.conf ( in /etc/mosquitto ) contain: allow_anonymous false ?

@Wolfgang_S yes mosquitto.conf contain allow_anonymous false.
Sorry I don’t undestrand what’s wrong? And why with MQTT explorer if I don’t put the password the connection is not allowed but in openhab yes :)?

ok…now works…
I change the listener in the mosquitto.conf from 1883 to 8883 and also disable safety connection and also disable select certificate. Now with the wrong password don’t work and with the correct password work.
Don’t ask me why this settings of selectors I just try and error but maybe someone expert of the MQTT protocol can clarify :grinning:

Thank a lot @Wolfgang_S @rpwong that you help me for the resolution!
Regards

listener 8883