MQTT - mosquitto - Error starting broker connection

I had MQTT running flawless in my previous setup and now after reinstalling everything it keeps losing the connecion to the broker. So I removed everything:

  • uninstalled binding (is it correct that there isn’t any 2.x version?)
  • uninstalled mosquitto
  • removed services/mqtt.cfg
  • deleted /var/lib/openhab2/config/org/openhab/mqtt.config

Afterwards I tried to reinstall:

  • Reinstalled binding
  • Reinstalled mosquitto via openhabian config
  • modified mqtt.cfg (mosquitto.url=tcp://192.168.0.143:1883) (is loaded under /var/lib/openhab2/config/org/openhab/mqtt.config)

but after saving I keep this errr

2018-01-09 00:37:39.213 [ERROR] [penhab.io.transport.mqtt.MqttService] - Error starting broker connection

org.eclipse.paho.client.mqttv3.MqttException: Unable to connect to server

at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:79) [235:org.openhab.io.transport.mqtt:1.11.0]

at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [235:org.openhab.io.transport.mqtt:1.11.0]

at java.lang.Thread.run(Thread.java:748) [?:?]

Caused by: java.net.ConnectException: Connection refused (Connection refused)

at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:?]

at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:?]

at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:?]

at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:?]

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:?]

at java.net.Socket.connect(Socket.java:589) ~[?:?]

at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70) ~[?:?]

… 2 more

Wouldn’t you typically want to edit /etc/openhab2/services/mqtt.cfg?

Have you tried using mosquitto_sub on your OH server to subscribe to your broker to verify connectivity?

Might also be helpful to turn debug or trace logging on for mqtt binding.

Yes - there is only the 1.x binding.

I installed the binding by adding “mqtt1” on the binding line in /etc/openhab2/services/addon.cfg.
Configuration is persisted in /etc/openhab2/services/mqtt.cfg
OH2 then creates config in /var/lib/openhab2/config/org/openhab/mqtt.config by itself.

BTW: You reinstalled the broker but is the service really running ? Or maybe the service is running but only bound to the local interface (127.0.0.1) ? I spent hours looking after “errors” like that … :vulcan_salute:

I finally found some time to work on this issue.

I noticed indeed that the mosquitto service was not running properly: Active: active (exited)
I reinstalled the service via the openhabian-config menu and saw 2 errors:

$ sed -i /password_file/d /etc/mosquitto/mosquitto.conf
sed: can't read /etc/mosquitto/mosquitto.conf: No such file or directory

$ sed -i /allow_anonymous/d /etc/mosquitto/mosquitto.conf
sed: can't read /etc/mosquitto/mosquitto.conf: No such file or directory

So I created this file:
sudo touch /etc/mosquitto/mosquitto.conf

Afterwards I did a reinstall of mosquitto (again via openhiab-config) and the error were gone + service is running properly.

I’ve tested it via mosquitto_sub and mqtt.fx (for windows): everything looks fine

All actions which are wirkong with mqtt are working again. thanks!

I just had the same error message as the OP after a re-install but my mosquitto.conf file was okay.

I re-installed mosquitto (with a stop/start too) - MQTT didn’t work.
I re-installed MQTT action (with a stop/start too) - MQTT didn’t work.
I re-installed MQTT binding (with a stop/start too) - MQTT didn’t work.
I re-installed mosquitto again (with a stop/start too) - MQTT didn’t work.
I re-installed MQTT action (with a stop/start too) - MQTT finally worked,

MQTT problems after an upgrade/re-install seems to be a common problem at the moment.

Hey guys , Did you find a solution for this problem .
I have the same issue and struggle too get the service running.
Have tried different settings in .cfg file and config, even installed on a different machine and get the same error.
Can you guys help me out and give me some hints where to look.

2018-02-17 11:50:37.435 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'globalcache.things’
2018-02-17 11:50:40.517 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://192.168.1.150:8080
2018-02-17 11:50:40.963 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://192.168.1.150:8443
2018-02-17 11:50:41.128 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-02-17 11:50:41.159 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-02-17 11:50:41.415 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-02-17 11:50:41.906 [INFO ] [e.internal.GlobalCacheHandlerFactory] - GlobalCache binding v2.1.0
2018-02-17 11:50:42.249 [INFO ] [b.core.service.AbstractActiveService] - Modbus Polling Service has been started
2018-02-17 11:50:42.277 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-02-17 11:50:42.278 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker’
2018-02-17 11:50:44.745 [ERROR] [penhab.io.transport.mqtt.MqttService] - Error starting broker connection
Unable to connect to server (32103) - java.net.ConnectException: Connection refused: connect
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:79)[200:org.openhab.io.transport.mqtt:1.10.0]
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)[200:org.openhab.io.transport.mqtt:1.10.0]
at java.lang.Thread.run(Unknown Source)[:1.8.0_151]
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)[:1.8.0_151]
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)[:1.8.0_151]
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)[:1.8.0_151]
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)[:1.8.0_151]
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)[:1.8.0_151]
at java.net.PlainSocketImpl.connect(Unknown Source)[:1.8.0_151]
at java.net.SocksSocketImpl.connect(Unknown Source)[:1.8.0_151]
at java.net.Socket.connect(Unknown Source)[:1.8.0_151]
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)[200:org.openhab.io.transport.mqtt:1.10.0]
… 2 more