Need help to setup MQTT Binding on OH2

help
openhab2
mqtt
Tags: #<Tag:0x00007fe051c723b8> #<Tag:0x00007fe051c72250> #<Tag:0x00007fe051c71fd0>

(Angelos) #3

Use Code Fences
fix your mqtt.cfg

broker.url=tcp://192.XX.XX.XX:1883
not
‘broker.url=tcp://192.XX.XX.XX:1883’

add the following line in mqtt.cfg

pid:org.openhab.mqtt

(SiHui) #4

1.x bindings don’t show up there, just 2.x bindings.

Start reading this thread:


(Rajeev) #5

I am still not able to bind the MQTT to Addons. Please find the Openhab (var/log/openhab2/openhab.log) and Mosquitto log file below.

Appreciate your help.

2018-05-30 23:41:11.387 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) se$
2018-05-30 23:41:12.597 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘MyHome.things’
2018-05-30 23:41:14.801 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-05-30 23:41:14.933 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-05-30 23:41:15.074 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-05-30 23:41:15.386 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-05-30 23:41:15.405 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘’
2018-05-30 23:41:15.705 [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) [219:org.openh$
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [219:org.openha$
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
2018-05-30 23:41:15.767 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘broker’
2018-05-30 23:41:15.802 [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) [219:org.openh$
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [219:org.openha$
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) ~[?:?]

here is Mosquitto log file
1527339623: Config loaded from /etc/mosquitto/mosquitto.conf.
1527339623: Opening ipv4 listen socket on port 1883.
1527339623: Opening ipv6 listen socket on port 1883.
1527339623: Opening ipv4 listen socket on port 1883.
1527339623: Error: Address already in use


(Vincent Regaud) #6

Can you post your mosquitto.conf, please


(Rajeev) #7

Here is Mosquitto.conf

listener 1883 192.168.XX.XX (Just masked the last two block of IP for obvious reason)
pid_file /var/run/mosquitto.pid

#persistence true
persistence_location /var/lib/mosquitto/
#persistence_file mosquitto.db

log_dest file /var/log/mosquitto/mosquitto.log
#log_dest syslog
#log_dest stdout
#log_dest topic
#log_type error
#log_type warning
#log_type notice
log_type information
connection_message true
log_timestamp true

allow_anonymous false
password_file /etc/mosquitto/pwfile
#listener 1883

#include_dir /etc/mosquitto/conf.d


(Angelos) #8

here are your working files:

mosquitto.conf

persistence false
log_dest file /var/log/mosquitto/mosquitto.log
log_type information
connection_message true
log_timestamp true
allow_anonymous false
password_file /etc/mosquitto/pwfile

mqtt.cfg

pid:org.openhab.mqtt
broker.url=tcp://192.XX.XX.XX:1883
broker.clientId=openhab2
broker.user=XXXX
broker.pwd=XXXX

Code Fences: Use them :slight_smile:


(Vincent Regaud) #9

@Dim

add port 1883 to the mosquitto.conf

port 1883
persistence false
log_dest file /var/log/mosquitto/mosquitto.log
log_type information
connection_message true
log_timestamp true
allow_anonymous false
password_file /etc/mosquitto/pwfile

(Rajeev) #10

Thanks !

As you suggested I made the changes to mosquitto.conf and mqtt.cfg file however I am still not able to see MQTT binding under configuration.

Here are the log files.

Openhab.log

2018-05-31 20:53:03.152 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘’
2018-05-31 20:53:13.476 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost
org.eclipse.paho.client.mqttv3.MqttException: Connection lost
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146) [223:org.openhab.io.transport.mqtt:1.12.0.RC2]
at java.lang.Thread.run(Thread.java:745) [?:?]
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267) ~[?:?]
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65) ~[?:?]
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107) ~[?:?]
… 1 more
2018-05-31 20:53:13.500 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to ‘’ was lost: Connection lost : ReasonCode 32109 : Cause : null
2018-05-31 20:53:13.502 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker ‘’

Mosquitto.log
527339623: mosquitto version 1.5 starting
1527339623: Config loaded from /etc/mosquitto/mosquitto.conf.
1527339623: Opening ipv4 listen socket on port 1883.
1527339623: Opening ipv6 listen socket on port 1883.
1527339623: Opening ipv4 listen socket on port 1883.
1527339623: Error: Address already in use


Moreover , I am getting a peculiar socket error when I run pi@raspberry:~$mosquitto .Not sure if it is related to the actual issue.

1527825741: New connection from 192.XXX.X.XX on port 1883.
1527825741: Client openhab2 already connected, closing old connection.
1527825741: Socket error on client openhab2, disconnecting.
1527825741: New client connected from 192.XXX.X.XX as openhab2 (c1, k60, u’username’).


(Angelos) #11

I doubt that you fixed your mqtt.cfg… post it here :slight_smile:


(Rajeev) #12

Thanks Dim for your quick response. Yes I did fixed the
sudo nano /etc/openhab2/services/mqtt.cfg

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

Note :Removed bracket before and after broker


(Angelos) #13

make sure that pid:org.openhab.mqtt is the first line within mqtt.cfg

You should see in the log a relevant entry


(Rajeev) #14

Yes , pid:org.openhab.mqtt is the first line within mqtt.cfg.

BTW, I just found these two below observation . Do you think it is causing the problem? looks like there are two instances running…

openhab cosole

openhab> config:property-list
.async = false
.ClientId = openhab2
.pwd = HomeHub
.qos = 1
.retain = true
.url = tcp://192.XX.XX.XX:1883
.user = username
broker.clientId = openhab2
broker.pwd = HomeHub
broker.url = tcp://192.168.XX.XX:1883
broker.user = username
service.pid = org.openhab.mqtt

** pi@raspeberry console**
pi@raspberrypi:~ $ dpkg -l | grep openhab
ii openhab2 2.3.0~RC2-1 all openhab2
ll openhab2


(Angelos) #15

yes, this is the problem (you have a old wrong broker config stored)

the pid: line should remove this and reload the config. I don’t understand why it’s not working for you… it should

anyway, follow these steps:

  1. stop OH2
  2. delete file /var/lib/openhab2/config/org/openhab/mqtt.config
  3. start OH2

(Rajeev) #16

I follow the above 3 steps

After step 3 when I went back to /var/lib/openhab2/config/org/openhab/mqtt.config
but it is still showing me
.clientId=“openhab2”
.pwd=“HomeHub”
.url=“tcp://192.168.X.XX:1883”
.user=“username”
service.pid=“org.openhab.mqtt”

however , /etc/openhab2/services/mqtt.cfg has different sequence of line…
pid:org.openhab.mqtt
.url=tcp://192.168.XX.XX:1883
.clientId=openhab2
.user=username
.pwd=HomeHub

do you think /var/lib/openhab2/config/org/openhab/mqtt.config is pulling the configuration from old instance? If yes how to delete it…? Is there anything we can do from Openhab console to delete the old configuration…


(Angelos) #17

check folder /etc/openhab2/services/ for extra cfg files which contain mqtt configs…
make sure that you are using the correct file… maybe that’s why the pid: line didn’t work…
Use Code fences… I am not sure that you are posting correctly the file contents (and by the way: your IP is RFC1918 so nothing to worry about :))


(Rajeev) #18

the only configuration file in /etc/openhab2/services/ folder are

  1. addons,cfg
  2. mqtt.cfg
  3. mqtt-eventbus.cfg

BTW, just to clarify : there are only two places where I have mqtt.cfg file.

  1. /var/lib/openhab2/config/org/openhab/mqtt.cfg
  2. /opt/openhab2/conf/services/mqtt.cfg
    and both the file has same content

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

note : bracket before and after broker


(Angelos) #19

so you should be ok now
try restarting OH2 and check the logs


(Angelos) #20

grrrr… what do you mean bracket?

Use Code Fences !!! (for the 5th time :))






(Vincent Regaud) #21

@rajeev2301

Please use the code fences. Thanks

Do the following, in order:

  1. uninstall the mqtt broker
  2. delere your mqtt.cfg from the conf/services folder
  3. clear the cache
  4. stop openhab (DON’T reboot)
  5. reboot your mqtt broker and wait 2 minutes
  6. reboot OH computer
  7. install the mqtt binding
  8. fill in the mqtt.cfg file with you broker details:
pid:org.openhab.mqtt
broker.url=tcp://192.XX.X.XX:1883
broker.clientId=openhab2
broker.user=username
broker.pwd=HomeHub

That’s all there should be. NOTHING else
make sure that pid:org.openhab.mqtt is the VERY FIRST LINE OF THE FILE

  1. stop openhab
  2. start openhab
  3. show us the logs at start up

(Rajeev) #22

Thanks Vincent for extending your help! also Thanks @Dim your patience :slight_smile: -( I am new to this environment )

@vzorglub
Before I goahead with your suggestion of reinstalling mqtt broker, please help me clarify few doubts

  1. Why the order/sequence of line ( in mqtt.cfg file) is different in mqtt.cfg file and the output which is getting from openhab console. ( plz ref below)
/etc/openhab2/services/mqtt.cfg file 
service.pid=org.openhab.mqtt
<broker>.url=tcp://192.XX.XX.XX:1883
<broker>.clientId=openhab2
<broker>.user=username
<broker>.pwd=HomeHub
openhab > config:edit org.openhab.mqtt
openhab> config:property-list

   <broker>.clientId = openhab2
   <broker>.pwd = HomeHub
   <broker>.url = tcp://192.XXX.X.XX:1883
   <broker>.user = username
   service.pid = org.openhab.mqtt

also, plz ref below the openhab log file , it says - Error starting broker connection. is that the reason why you want me to reinstall mqtt broker? if yes , please let me know do i need to uninstall & install both mosquitto and mosquitto-clients or only mosquitto ?? (BTW i use this source to download mqtt package : http://repo.mosquitto.org/debian/mosquitto-stretch.list) ?

2018-06-01 00:18:42.709 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection '<broker>'
2018-06-01 00:18:43.010 [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) [223:org.openhab.i$
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [223:org.openhab.io$
        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) ~[?:?]

  1. Sencondly , when I run
pi@raspberrypi:~ $ dpkg -l | grep openhab 

ii  openhab2                              2.3.0~RC2-1                          all          openhab2
ll          openhab2

it looks like there are two instances of openhab2. ( is my understanding correct??) if yes, do I need to uninstall openhab as well and do a fresh installation.??

Appreciate your help!