Need help to setup MQTT Binding on OH2

help
openhab2
mqtt
Tags: #<Tag:0x00007fe0570c26e8> #<Tag:0x00007fe0570c24e0> #<Tag:0x00007fe0570c2378>

(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!


(Vincent Regaud) #23

WAIT!!!

  • Remove the < and the > from the <broker> in your mqtt.conf
  • Change the first line to: pid:org.openhab.mqtt - NOT service.pid:org.openhab.mqtt
  • Show me your log

(Rajeev) #24

Here is the changed mqtt.cfg file

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

/var/log/openhab2/openhab.log

2018-06-01 01:31:05.886 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 01:31:06.175 [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) [225:org.openhab.io.transport.mqtt:1.12.0$
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [225: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

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

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

/var/log/mosquitto/mosquitto.log

1527339623: 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
```

(Vincent Regaud) #25

Ok, so your broker is refusing the connection from openHAB
The main reason for that are incorrect usernames and password settings.

Show me your mosquitto.conf file
It should be located in /etc/mosquitto

Answers to your questions above:

It doesn’t matter. OH is pulling the info from your mqtt.cfg and parsing it in the /var/lib/openhab2/config/org/openhab/mqtt.config automatically. DO NOT TOUCH /var/lib/openhab2/config/org/openhab/mqtt.config. Your are a beginner, let OH handle these things for you.

Your understanding is incorrect. Your console output is showing the main process and the subprocess


(Rajeev) #26

/etc/mosquitto/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

(Vincent Regaud) #27

Let’s go back to basic.
Follow me exactly. Don’t try to improvise
I am not putting your security at risk because you are doing it all in your LAN
When it works, we will add the username and password back in use
Let’s go…

Change the allow_anonymous to true
and comment out the password_file line

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 true
#password_file /etc/mosquitto/pwfile

Then change your OH mqtt.cfg to:

mqtt.cfg

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

Then stop and restart mosquitto
Then stop and restart openHAB
Show your OH start up log


(Rajeev) #28

Here you go!

I followed the following steps

pi@raspberrypi:~ $ sudo systemctl stop mosquitto.service
pi@raspberrypi:~ $ sudo /etc/init.d/mosquitto start
[ ok ] Starting mosquitto (via systemctl): mosquitto.service.
pi@raspberrypi:~ $ sudo systemctl stop openhab2.service
pi@raspberrypi:~ $ sudo systemctl start openhab2.service

OH startup logfile…

2018-06-01 02:13:06.721 [WARN ] [g.dispatch.internal.ConfigDispatcher] - The file /etc/openhab2/services/mqtt.cfg subsequen$
2018-06-01 02:13:06.734 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-06-01 02:13:06.740 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 02:13:06.777 [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) [225:org.openhab.io.tra$
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [225:org.openhab.io.tran$
        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-06-01 02:18:18.090 [INFO ] [basic.internal.servlet.WebAppServlet] - Stopped Basic UI
2018-06-01 02:18:27.479 [INFO ] [penhab.io.transport.mqtt.MqttService] - Stopping broker connection '192.XXX.X.XX'
2018-06-01 02:18:27.482 [INFO ] [penhab.io.transport.mqtt.MqttService] - Stopping broker connection 'broker'
2018-06-01 02:18:28.293 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Stopped Paper UI
2018-06-01 02:18:28.328 [INFO ] [panel.internal.HABPanelDashboardTile] - Stopped HABPanel
2018-06-01 02:18:28.344 [INFO ] [er.internal.HomeBuilderDashboardTile] - Stopped Home Builder
2018-06-01 02:18:28.376 [INFO ] [.dashboard.internal.DashboardService] - Stopped Dashboard
2018-06-01 02:18:59.026 [WARN ] [g.dispatch.internal.ConfigDispatcher] - The file /etc/openhab2/services/mqtt.cfg subsequen$
2018-06-01 02:18:59.090 [INFO ] [er.internal.HomeBuilderDashboardTile] - Started Home Builder at /homebuilder
2018-06-01 02:18:59.963 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://192.X.X.XX:8080
2018-06-01 02:18:59.967 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://192.XXX.X.XX:8443

/etc/openhab2/services/mqtt.cfg

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

(Vincent Regaud) #29

OK,
Now change the following line in your mqtt.cfg:

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

(Vincent Regaud) #30

Did that work?


(Rajeev) #31

Good Morning Vincent !

No, it did not work. Here is the OH log…

2018-06-01 08:46:44.929 [WARN ] [g.dispatch.internal.ConfigDispatcher] - The file /etc/openhab2/services/mqtt.cfg subsequently defines the exclusive PID 'org.$
2018-06-01 08:46:44.942 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-06-01 08:46:44.945 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 08:46:44.980 [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) [225:org.openhab.io.transport.mqtt:1.12.0.RC2]
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [225: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) ~[?:?]
        ... 2 more


(Vincent Regaud) #32

reboot the pi


(Angelos) #33

it seems that mosquitto is not running (it doesn’t seem to be an auth issue)
it is strange but if you don’t put anything (port, listener, etc) in the config file for networking… it works (it uses the defaults) :stuck_out_tongue:
(I saw this recently on my rPi3 after I upgraded mosquitto to v1.5)

try the following for 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

(Rajeev) #34

@Vincent

I did reboot pi. Here is OH log

2018-06-01 08:57:55.755 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-06-01 08:57:56.953 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'MyHome.things'
2018-06-01 08:57:58.897 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-06-01 08:57:59.058 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-06-01 08:57:59.136 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-06-01 08:57:59.544 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-06-01 08:57:59.551 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'
2018-06-01 08:57:59.826 [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) [225:org.openhab.io.transport.mqtt:1.12.0.RC2]
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650) [225: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) ~[?:?]