Need help to setup MQTT Binding on OH2

Hi

After stretching for numerous hours and scratching my head in solving MQTT binding issue in Openhab2, I have decided to write in this forum to seek help.

My Scenario :

I am not able to bind MQTT into openhab2 . I tried installing and uninstalling MQTT Binding(binding-mqtt1 - 1.12.0.RC2) using PaperUI -> Addons multiple times but not sure why it is not reflecting in Configuration-> Bindings screen.I also tried deleting /org/openhab/mqtt.config few times but no change in the outcome.

Here are the log file details. openhab2/openhab.log

018-05-30 01:39:13.292 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-05-30 01:39:13.487 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-05-30 01:39:13.585 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-05-30 01:39:13.941 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-05-30 01:39:13.952 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ā€˜ā€™
2018-05-30 01:39:14.196 [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) [217:org.openhab.io.transport.mqtt:1.12.0.RC2]
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [217:org.openhab.io.transport.mqtt:1.12.0.RC2]
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) ~[?:?]

Please let me know if I am missing anything.

Thanks!

here are my configuration files

services/mqtt.cfg ( for obvious reason i have masked the IP address,User & Pwd_
ā€˜broker.url=tcp://192.XX.XX.XX:1883ā€™
broker.clientId=openhab2
broker.user=XXXX
broker.pwd=XXXX
note : bracket is included in the original syntaxā€¦

/etc/openhab2/services/addons.cfg
binding = mqtt1
action =pushover

I think My Mosquitto server is working file since I am able to publish and subscribe though command lineā€¦

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
1 Like

1.x bindings donā€™t show up there, just 2.x bindings.

Start reading this thread:

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

Can you post your mosquitto.conf, please

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

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:

@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
1 Like

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ā€™).

I doubt that you fixed your mqtt.cfgā€¦ post it here :slight_smile:

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

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

You should see in the log a relevant entry

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

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

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ā€¦

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 :))

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

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

grrrrā€¦ what do you mean bracket?

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