MQTT Connection not working correctly

You can copy and paste code here too.

Change:
broker.url=tcp://localhost:1883
to:
broker.url=tcp://127.0.0.1:1883

It doesn’t seem to make much sense but sometimes it works

Restart OH and monitor the openhab.log for messages about mqtt

After item changes, sometimes there is a need to clean cache and/or tmp folders.

Now:
2018-09-09 22:15:20.242 [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) [209:org.openhab.io.transport.mqtt:1.12.0]

at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [209:org.openhab.io.transport.mqtt:1.12.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

had that before, have to start the mosquitto manually.

Mosquitto started, but still no message in MQTT Lens (and devices also not switching)

Have you double checked the mosquitto user name and password?

Yes.

Next question, do you have the MQTT action installed?

Yes, the MQTT Binding is installed (PaperUI).

No, the MQTT action?

Are you by any chance running the snapshot version of OH? I had the same problem a few days ago and spent about a day and a half messing around with it. I had to revert back to the stable version for things to start working again.

Mine was specifically w/ the eventbus, but I don’t have any other MQTT things going on w/ the instance I was testing this on. (It’s a detached garage that has it’s own OH for lights and such).

My post : MQTT Eventbus stopped working?

How can i check this?

Go to PaperUI → Addons → Actions tab and see if it is installed:

It is installed NOW.
Do i have to configure anything for it?

Still not sending a MQTT Message (MQTT Lens)

After reboot always:

2018-09-12 20:04:39.154 [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) [209:org.openhab.io.transport.mqtt:1.12.0]

at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [209:org.openhab.io.transport.mqtt:1.12.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

So i’m starting it with “mosquitto -d”, is this correct?
Mosquitto is installed through openhabian-config

Yes, make your settings in mqtt-eventbus.cfg which should have been created after installing the binding.

“# Name of the broker as it is defined in the openhab.cfg. If this property is n$
broker=broker”

Was already set (done a time ago)

You need to set that option to the same broker name as in your mqtt binding.

1 Like

mqtt-eventbus.cfg:

broker=mosquitto
commandPublishTopic=/in/${item}
statePublishTopic=/state/${item}
stateSubscribeTopic=/out/${item}
commandSubscribeTopic=/command/${item}/state

or whatever topic you prefer.

mqtt.cfg:

mosquitto.url=tcp://localhost:1883

I think i have to use “broker” instead of mosquitto,

Thats what he was telling you.

BTW why do you need the mqtt ACTION binding for turning on and off a switch? I dont use that binding and have nearly a dozen esp’s working with OH via mqtt.

I may be wrong but I think the question was ask to see if you had it installed, if so then, uninstall it. The action binding has (or had?) a history of interfering with the mqtt binding. So unless you need it, uninstall both mqtt bindings, clean your cache and reinstall the mqtt binding only.

1 Like

Thank you.
I think I’m going to reinstall Openhabian.
I’m writing if it helped.