Problem connecting to Mosquitto broker using MQTT binding


I’ve set Mosquitto MQTT broker using mosquitto.conf (username and password set by using mosquitto_passwd), and I can connect to it from Owntracks on Android. After setting up MQTT binding, Mosquitto just shows an error message in terminal window (socket error on client <unknown>), and OpenHAB disconnects. In MQTT.cfg I’ve set clientId, but it’s not displayed when this error message is shown. Anyone had similar problem? I would like to use MQTT for both, Owntracks and Sonoff switches, but just can’t make it work. I’m using OpenHAB 2 on Windows 7.

Best regards,

What specifically is your mqtt.cfg (don’t post your passwords).

Are you using TLS encryption on Mosquitto?

Do you see anything in openhab.log?

Hello @rlkoshak!

Sorry for the late reply. This is my mosquitto.conf that I’m using with -c parameter:

listener 8883
persistence false
log_dest syslog
log_dest stdout
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
allow_anonymous false
password_file pwfile 

With these settings, OwnTracks can connect (even from outside of the local LAN) without problems. These are settings in MQTT.cfg file (used example from the documentation):


I’ve created username and password using mosquitto_passwd and OwnTracks connect successfully with these credentials. I’ve also tried using tcp://, and changing clientId to a number, but without success. Every time I’ve saved changes to MQTT.cfg in mosquitto terminal window I’m getting error message:
socket error on client <unknown>

I’ve also tried adding item and sitemap entry, but without any change. Thank you for your help.

Best regards,

I don’t think OH supports ssl connections.

You can create another listener in your mosquitto config that doesn’t use encryption but only accepts connections on localhost or your LAN and use that to connect to with OH. I think the default listener is set up in this way.

Then your URL for mqtt.cfg will be tcp:// instead of ssl://.


I’ve just tried connecting with a default listener bind to localhost, and it worked. At first mosquitto showed error message, but it looks like MQTT binding was trying to connect on port 8883, even though MQTT.cfg was set to tcp://localhost:1883, but after a restart, it connected successfully. Thank you for your help.

Best regards,