Need help to setup MQTT Binding on OH2

Comment out the clientId line in the mqtt.cfg
Openhab will generate a uniqur one automatically

DON’T use 127.0.0.1 in mqtt.fx!
Use the IP of the raspberry

127.0.0.1 means local machine or this machine
So use 127.0.0.1 in the mqtt.cfg because OH and mosquitto are on the same machine

mqtt.cfg:

pid:org.openhab.mqtt
broker.url=tcp://127.0.0.1:1883
#broker.clientId=openhab2
broker.user=username
broker.pwd=xxxxxx

Yes that’s what I thought when I asked him
The series of:

2018-06-01 15:01:10.936 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 15:02:10.936 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 15:03:10.937 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 15:04:10.937 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 15:05:10.936 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'

Was pointing to that

Yes , MQTT.fx is now connected to broker… I am able to publish and subscribe messages…

in RPi, mqtt.cfg

pid:org.openhab.mqtt
broker.url=tcp://172.0.0.1:1883
#broker.clientId=openhab2
broker.user=username
broker.pwd=HomeHub

Well? That should work now


127.0.0.1

yes , I have updated that

pid:org.openhab.mqtt
broker.url=tcp://127.0.0.1:1883
broker.clientId=openhab2
broker.user=username
broker.pwd=HomeHub

current status of log OH log file

018-06-01 20:59:12.738 [INFO ] [penhab.io.transport.mqtt.MqttService] - Stopping broker connection '192.168.1.47'
2018-06-01 20:59:12.742 [INFO ] [penhab.io.transport.mqtt.MqttService] - Stopping broker connection 'broker'
2018-06-01 20:59:12.891 [INFO ] [core.karaf.internal.FeatureInstaller] - Uninstalled 'openhab-binding-mqtt1'
2018-06-01 20:59:21.609 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-06-01 20:59:21.618 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 20:59:21.989 [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) [213:org.openhab.io.transport.mqtt:1.12.0]
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [213:org.openhab.io.transport.mqtt:1.12.0]
        at java.lang.Thread.run(Thread.java:745) [?:?]
Caused by: java.net.ConnectException: 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


change this setting to something else

pid:org.openhab.mqtt
broker.url=tcp://127.0.0.1:1883
broker.clientId=openhab254213
broker.user=username
broker.pwd=HomeHub

I made the suggested changes to mqtt.cfg file but looks like problem still persist

pid:org.openhab.mqtt
broker.url=tcp://127.0.0.1:1883
broker.clientId=openhab254213
broker.user=username
broker.pwd=HomeHub

2018-06-01 22:47:22.055 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-06-01 22:47:24.435 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'MyHome.things'
2018-06-01 22:47:26.605 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-06-01 22:47:26.773 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-06-01 22:47:26.888 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-06-01 22:47:26.892 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 22:47:27.044 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-06-01 22:47:27.145 [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) [213:org.openhab.io.transport.mqtt:1.12.0]
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [213:org.openhab.io.transport.mqtt:1.12.0]
        at java.lang.Thread.run(Thread.java:745) [?:?]
Caused by: java.net.ConnectException: 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


anything interesting in mosquitto.log?

it should have worked by now…

post the contents of /var/lib/openhab2/config/org/openhab/mqtt.config also to check something

post also the output of this linux command (no need to mask IP Addresses of 192.168.x.y kind… they are not routable over the internet).

netstat -atn |grep 1883

make sure that this is not installed:

Yes , MQTT Action is not installed. I double checked it…

/var/lib/openhab2/config/org/openhab/mqtt.config

broker.clientId="openhab254213"
broker.pwd="HomeHub"
broker.url="tcp://127.0.0.1:1883"
broker.user="username"
service.pid="org.openhab.mqtt"
pi@raspberrypi:~ $ netstat -atn |grep 1883
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN     
tcp6       0      0 :::1883                 :::*                    LISTEN  

ok… try to disable authentication for mqtt to test:

/etc/openhab2/services/mqtt.cfg:

pid:org.openhab.mqtt
broker.url=tcp://127.0.0.1:1883
broker.clientId=openhab254213
#broker.user=username
#broker.pwd=HomeHub

/etc/mosquitto/mosquitto.conf

allow_anonymous true

restart mosquitto and OH2 services

systemctl restart mosquitto
systemctl restart openhab2

monitor both mosquitto.log and openhab.log and post new log info

here are the log file…

sudo nano /var/log/openhab2/openhab.log

2018-06-02 00:22:23.868 [WARN ] [g.dispatch.internal.ConfigDispatcher] - The file /etc/openhab2/services/mqtt.cfg subsequently defines the exclusive PID $
2018-06-02 00:22:24.085 [INFO ] [er.internal.HomeBuilderDashboardTile] - Started Home Builder at /homebuilder
2018-06-02 00:22:25.723 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://192.168.1.47:8080
2018-06-02 00:22:25.726 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://192.168.1.47:8443
2018-06-02 00:22:34.223 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Myhome.items' has errors, therefore ignoring it: [3,23]: mi$

2018-06-02 00:22:38.088 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-06-02 00:22:39.938 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'MyHome.things'
2018-06-02 00:22:42.039 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-06-02 00:22:42.228 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-06-02 00:22:42.335 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-06-02 00:22:42.338 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-02 00:22:42.532 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel

/var/log/mosquitto/mosquitto.log

1527876777: New connection from ::1 on port 1883.
1527876777: New client connected from ::1 as mosqsub|1876-raspberryp (c1, k60, $
1527876781: New connection from ::1 on port 1883.
1527876781: New client connected from ::1 as mosqpub|1877-raspberryp (c1, k60, $
1527876781: Client mosqpub|1877-raspberryp disconnected.
1527876809: Socket error on client mosqsub|1876-raspberryp, disconnecting.
1527876809: mosquitto version 1.5 terminating

so… it works now and your problem is your username/password combo…

I will relook into username/password combo however MQTT bindings is not showing up under configuration -> services.
I followed the below steps in the link correctly but I am not able to move forward in step 3 ( binding settings) . I tried installing /uninstalling ( MQTT Binding (binding-mqtt1) ) multiple times.

( https://community.openhab.org/t/mqtt-binding-v1-11-getting-started-101/33958) 

I have created below item file but not able to link it to bindings…

Number:Temperature Temperature  "Outside Temperature [%.1f %unit%]" { channel="yahooweather:weather:berlin:temperature" }
Number Humidity "humidity [%.1f]" {mqtt="<[broker:RF24SN/in/2/2:state:default]"}
Switch mySwitch {mqtt=">[broker:RF24SN/out/2/1:command:ON

it will never show
there is nothing that you can configure via PaperUI when it comes to the MQTT Binding v1

full path and filename please for the items file
last line seems to be cut off
check openhab.log for warnings/errors when parsing the items file

1 Like
Switch mySwitch { mqtt=">[broker:RF24SN/out/2/1:command:*:default" }

Action the switch in your UI, what happens in mqtt.fx?

Full path for item file

/etc/openhab2/items/Myhome.items

Yes, MQTT.fx is communicating using “RF24SN/out/2/1” publish and subscribe… but how Can I bind it to UI…?

READ THE DOCS…
AND WHEN YOU HAVE FININSHED READ THEM AGAIN!!!

1 Like

@rajeev2301
By the way, a little thank you for getting your stuff working would have been nice, after all 2 of us two 2 days to get through to you.

Some of the rest now you will have to figure out by yourself. The are the docs, the forum.
Search the forum before asking trivial questions. Chances are, someone asked the question before.

But ALL you need is in the docs. Read them, again and again.
Follow the docs, step by step. Don’t skip any
Check for typos
Don’t try to improvise. You do NOT know better.

openHAB is hard. At the beginning you WILL struggle. But that struggle will make you learn. If we tell you everything then you won’t learn and to be honest we have better things to do than telling you stuff that’s in the docs, that you should have been reading in the first place.

Good luck

1 Like