Need help to setup MQTT Binding on OH2

sure !

Just another input for your guys while I am trying to install Mosquitto again… I had MQTT.fx runnning on another PC and till yesterday it was connecting properly with MQTT broker… In fact I was able to publish and subscribe messages…

now… MQTT.fx cannot connect to the broker… correct?

Yes

mosquitto ist kaput!! the mosquitto is dead, we don’t really know what you have been trying to do to get it back up and running so I think it’s better that you start from scracth and remove it and re-install it

@Dim, what do you think?

1 Like

yes , that what i am doing now… I have purged mosquitto… and following the steps you mentioned in previous thread…

There is an open issue with Eclipse with regards to Mosquitto v1.5 on Debian Jessie (most likely this is what Rajeev) is running

If you specify any networking options in the config file: It launches the default plus whatever you defined in your mosquitto.conf… causing a conflict and you get:

Error: Address already in use

Some people say that this can be fixed if you upgrade Jessie to Stretch which will update libwebsockets.so
There is no root-cause identified yet and no definite solution…

more info on:

  1. Mosquitto stopped working after upgrade to v 1.5
  2. https://github.com/eclipse/mosquitto/issues/825
  3. https://github.com/eclipse/mosquitto/issues/837#issuecomment-392607455
1 Like

quick question:

I am using below source to download mosquitto. Do you have any other recommendation?

wget https://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
sudo wget http://repo.mosquitto.org/debian/mosquitto-stretch.list 
sudo -i
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
sudo apt-get update

Use the raspberry pi source
You don’t need:

wget https://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
sudo wget http://repo.mosquitto.org/debian/mosquitto-stretch.list

If you did that before you need to remove the repo from the repo list.
Sorry I got ahead of myself

The raspberry pi repository has mosquitto in it
Use that one as it is GUARANTEED to work with your pi

Who told you to install another repository for your rasperry pi is a twit.

Just do:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mosquitto
1 Like

btw: @rajeev2301 is your Raspbian based on Debian Jessie (8) or Stretch (9)?

output of

lsb_release -a
pi@raspberrypi:~ $ lsb_release -a

|Distributor ID:|Raspbian|
|---|---|
|Description:|Raspbian GNU/Linux 9.4 (stretch)|
|Release:|9.4|
|Codename:|stretch|

sudo apt-get purge mosquitto
sudo reboot
...
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mosquitto
1 Like

I have reinstalled mosquitto

here is the log OH file and mosquitto log file.

2018-06-01 11:44:32.943 [INFO ] [er.internal.HomeBuilderDashboardTile] - Started Home Builder at /homebuilder
2018-06-01 11:44:34.546 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://192.XX.X.XX:8080
2018-06-01 11:44:34.550 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://192.XX.X.XX:8443
2018-06-01 11:45:09.155 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Myhome.items' has errors, therefore i$

2018-06-01 11:45:13.705 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-06-01 11:45:14.899 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'MyHome.things'
2018-06-01 11:45:17.121 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-06-01 11:45:17.311 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-06-01 11:45:17.516 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-06-01 11:45:17.523 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 11:45:17.683 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-06-01 11:45:17.758 [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) [205:org.openhab.io.transport.m$
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [205:org.openhab.io.transport.mq$
        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) ~[?:?]

Mosquitto log file

1527876354: Opening ipv6 listen socket on port 1883.
1527876424: New connection from 127.0.0.1 on port 1883.
1527876424: New client connected from 127.0.0.1 as paho51879022739 (c1, k60).
1527876760: New connection from ::1 on port 1883.
1527876760: New client connected from ::1 as mosqpub|1865-raspberryp (c1, k60, $
1527876760: Client mosqpub|1865-raspberryp disconnected.
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


BTW, MQTT.fx is successfully publishing and receiving messages from broker… Which essentially means mosquitto is working file.

here is output from OH console
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

Mqtt.cfg please

/etc/openhab2/services/mqtt.cfg

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

I also encountered one strange thing while running mosquitto command from Pi. it is trying to close old connection and opening a new one. plz ref below…

pi@raspberrypi:~ $ mosquitto
1527890040: New connection from 192.XXX.X.XX on port 1883.
1527890040: Client openhab2 already connected, closing old connection.
1527890040: Socket error on client openhab2, disconnecting.
1527890040: New client connected from 192.XXX.X.XX as openhab2 (c1, k60, u'username').

do you have the MQTT Action (not binding) addon installed? (if yes: uninstall it and restart OH2)

also, change the IP of the broker in /etc/openhab2/services/mqtt.cfg

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

From what I understand, the Mosquitto Broker is running on the same host as OH2… correct?

What settings do you use in MQTT.fx

In openhab mqqt.cfg do this:

broker.url=tcp://127.0.0.1:1883
broker.clientId=openhab2
broker.user= SAME AS MQTT.fx
broker.pwd= SAME AS MQTT.fx

NO , I don;t have any other binding except mqtt

from addons.cfg file.

binding = mqtt1

changed mqtt.cfg

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

yes, MQTT broker is running on the same host as OH2…

Here is the log file after making the above changes…

2018-06-01 14:54:00.929 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'broker' was lost: Connection los$
2018-06-01 14:54:00.932 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try resto$
2018-06-01 14:54:10.939 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 14:55:10.935 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 14:56:10.936 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 14:57:10.936 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 14:58:10.936 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 14:59:10.935 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 15:00:10.935 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
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'
2018-06-01 15:06:10.936 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 15:06:54.718 [WARN ] [g.dispatch.internal.ConfigDispatcher] - The file /etc/openhab2/services/mqtt.cfg subsequentl$
2018-06-01 15:06:54.729 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-06-01 15:06:54.734 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 15:07:54.813 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 15:07:54.813 [ERROR] [penhab.io.transport.mqtt.MqttService] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttException: MqttException
        at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38) [207:org.open$
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664) [207:org.openhab.io.transp$
        at java.lang.Thread.run(Thread.java:745) [?:?]
Caused by: java.net.SocketTimeoutException: connect timed out
        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) ~[?:?]
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) ~[?:?]

What clientId are you using in MQTT.fx?

I bet 10 EUR he is using the same (openhab2) :slight_smile: (or in another device)

@rajeev2301: clientId needs to be unique for every client. Change it from openhab2 to something else in /etc/openhab2/services/mqtt.cfg

By the way: The MQTT Action is not a binding. Check in PaperUI-> Add-Ons -> Actions if it is installed