Openhab 1.8.3 not connect to MQTT broker in RasPi

Hi to everyone,

I’m more or less new in this world and i’m trying to build a system with Raspberry server and nodemcu (esp8266) devices.

My RasPi is working as a broker for MQTT and also have installed openhab.

First of all i made some test with nodemcu device and MQTT broker (RasPi) and all works well, because i can see message published, and also i see how led is switch on/off.

Now i want switch on/off led by openhab, but doesn’t work. I see logs in openhab and the problem seems that openhab can’t binding with MQTT i dunno why.

This is the log that i see when i start openhab process in the RasPi:

osgi> 2016-07-10 12:22:22.229 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.8.3).
2016-07-10 12:22:24.912 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
2016-07-10 12:22:25.147 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
2016-07-10 12:22:25.158 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-07-10 12:22:25.160 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'broker’
2016-07-10 12:22:25.167 [DEBUG] [o.i.t.m.i.MqttBrokerConnection] - Creating new client for ‘tcp://192.168.1.140:1883’ using id ‘openhab’ and file store '/tmp/broker’
2016-07-10 12:22:25.225 [ERROR] [.io.transport.mqtt.MqttService] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttPersistenceException: Persistence already in use
at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:108) ~[na:na]
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.(MqttAsyncClient.java:273) ~[na:na]
at org.eclipse.paho.client.mqttv3.MqttClient.(MqttClient.java:222) ~[na:na]
at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.openConnection(MqttBrokerConnection.java:297) ~[na:na]
at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.start(MqttBrokerConnection.java:115) ~[na:na]
at org.openhab.io.transport.mqtt.MqttService.updated(MqttService.java:112) ~[na:na]

When I try to switch on light by openhab website, i see how message is sending by openhab logs, but no reply or message on MQTT:

2016-07-10 12:55:01.420 [INFO ] [runtime.busevents ] - lamp1 received command ON
2016-07-10 12:55:14.795 [WARN ] [.httpclient.HttpMethodDirector] - Unable to respond to any of these challenges: {oauth=OAuth oauth_problem=“OST_OAUTH_PARAMETER_ABSENT_ERROR”, realm=“yahooapis.com”}
2016-07-10 12:55:14.796 [WARN ] [g.openhab.io.net.http.HttpUtil] - Method failed: HTTP/1.1 401 Unauthorized
2016-07-10 12:55:14.858 [INFO ] [runtime.busevents ] - Weather_Humidity state updated to

Please, can someone help me?

Thanks

Hi Again,

I stopped openhab process and started again, and now the error is this one:

2016-07-10 18:19:38.313 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-07-10 18:19:38.315 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'broker’
2016-07-10 18:19:38.321 [DEBUG] [o.i.t.m.i.MqttBrokerConnection] - Creating new client for ‘tcp://192.168.1.140:1883’ using id ‘openhab’ and file store '/tmp/broker’
2016-07-10 18:19:38.480 [ERROR] [.io.transport.mqtt.MqttService] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttPersistenceException: MqttException
at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.getFiles(MqttDefaultFilePersistence.java:244) ~[na:na]
at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.clear(MqttDefaultFilePersistence.java:288) ~[na:na]
at org.eclipse.paho.client.mqttv3.internal.ClientState.clearState(ClientState.java:179) ~[na:na]
at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:762) ~[na:na]
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:110) ~[na:na]

please can someone help me?

thanks

Hi,

After doing some changes, now i have new errors that say that every time i lose connection…

2016-07-10 21:04:28.272 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to ‘broker’ was lost: Connection lost : ReasonCode 32109 : Cause : null
2016-07-10 21:04:28.273 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'broker’
2016-07-10 21:04:38.275 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection ‘broker’

But with raspberry i always i’m connected… any suggestions?

thanks

My setup is identical - including a nodemcu esp8266 device, so I’d like to help, but I’m not sure from your last post if you even still have a problem.

Is OH continuously disconnecting from the broker?

Hello,

Thanks for reply.

Yes, as you can see in last post, more or less each 10 seconds i see in logs of openhab that connection was lost

2016-07-11 10:52:56.253 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to ‘broker’ was lost: Connection lost : ReasonCode 32109 : Cause : null
2016-07-11 10:52:56.254 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'broker’
2016-07-11 10:52:57.048 [WARN ] [.httpclient.HttpMethodDirector] - Unable to respond to any of these challenges: {oauth=OAuth oauth_problem=“OST_OAUTH_PARAMETER_ABSENT_ERROR”, realm=“yahooapis.com”}
2016-07-11 10:52:57.050 [WARN ] [g.openhab.io.net.http.HttpUtil] - Method failed: HTTP/1.1 401 Unauthorized
2016-07-11 10:52:57.101 [INFO ] [runtime.busevents ] - Weather_Temperature state updated to

2016-07-11 10:53:06.256 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'broker’
2016-07-11 10:53:16.310 [ERROR] [o.i.t.m.i.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:138) [mqtt-client-0.4.0.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: java.io.EOFException: null
at java.io.DataInputStream.readByte(DataInputStream.java:267) ~[na:1.8.0_65]
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:56) ~[na:na]
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:100) [mqtt-client-0.4.0.jar:na]
… 1 common frames omitted
2016-07-11 10:53:16.312 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to ‘broker’ was lost: Connection lost : ReasonCode 32109 : Cause : null
2016-07-11 10:53:16.313 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'broker’
2016-07-11 10:53:26.315 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'broker’
2016-07-11 10:53:36.367 [ERROR] [o.i.t.m.i.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:138) [mqtt-client-0.4.0.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: java.io.EOFException: null
at java.io.DataInputStream.readByte(DataInputStream.java:267) ~[na:1.8.0_65]
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:56) ~[na:na]
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:100) [mqtt-client-0.4.0.jar:na]
… 1 common frames omitted
2016-07-11 10:53:36.370 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to ‘broker’ was lost: Connection lost : ReasonCode 32109 : Cause : null
2016-07-11 10:53:36.371 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'broker’
2016-07-11 10:53:46.373 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection ‘broker’

And i don’t see anything when i subscribe to topic and try to switch on/off led by OH website

By nodemcu i can see that mosquitto always is working and don’t have any problem.

thanks

It looks like OH is having difficulty reading from where the MQTT is configured. Can you paste the MQTT Transport section of your openhab.cfg file?

Hi,
Well today I reinstalled Raspbian, MQTT and Openhab.

And now I have different results on openhab logs :slight_smile:, but i think that continue without working. These are the logs:

osgi> 2016-07-11 20:37:00.638 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.8.3).
2016-07-11 20:37:03.470 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
2016-07-11 20:37:03.608 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
2016-07-11 20:37:03.621 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-07-11 20:37:03.623 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'broker’
2016-07-11 20:37:08.980 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
2016-07-11 20:37:12.565 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test1.sitemap’
2016-07-11 20:37:13.342 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'logging.persist’
2016-07-11 20:37:13.404 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'exec.persist’
2016-07-11 20:37:13.425 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'db4o.persist’
2016-07-11 20:37:13.440 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist’
2016-07-11 20:37:13.562 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'demo.script’
2016-07-11 20:37:13.834 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'test1.items’
2016-07-11 20:37:14.416 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /classicui/openhab.app
2016-07-11 20:37:19.038 [INFO ] [.service.AbstractActiveService] - HTTP Refresh Service has been started
2016-07-11 20:37:19.073 [INFO ] [.service.AbstractActiveService] - NTP Refresh Service has been started
2016-07-11 20:37:19.090 [WARN ] [o.p.m.i.MqttPersistenceService] - mqtt-persistence:broker
2016-07-11 20:37:19.091 [WARN ] [o.p.m.i.MqttPersistenceService] - mqtt-persistence:topic
2016-07-11 20:37:19.092 [WARN ] [o.p.m.i.MqttPersistenceService] - mqtt-persistence:message
2016-07-11 20:37:19.160 [INFO ] [.p.rrd4j.internal.RRD4jService] - Removing invalid defintion component = null heartbeat = 0 min/max = 0.0/0.0 step = 0 0 archives(s) = [] 0 items(s) = []
2016-07-11 20:37:57.709 [INFO ] [runtime.busevents ] - lamp1 received command ON

As you can see in last line, by openhab website i switched on lamp, but in topic where i’m subscribed, i don’t see anything.

This is de openhab.cfg transport configuration:

#######################################################################################

Transport configurations

#######################################################################################

################################# MQTT Transport ######################################

Define your MQTT broker connections here for use in the MQTT Binding or MQTT

Persistence bundles. Replace with a id you choose.

URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883

#mqtt:.url=tcp://:1883
mqtt:broker.url=tcp://localhost:1883

Optional. Client id (max 23 chars) to use when connecting to the broker.

If not provided a default one is generated.

#mqtt:.clientId=
mqtt:broker.clientId=openhab

Optional. User id to authenticate with the broker.

mqtt:.user=

Optional. Password to authenticate with the broker.

#mqtt:.pwd=

Optional. Set the quality of service level for sending messages to this broker.

Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2

(Deliver exactly once). Defaults to 0.

#mqtt:.qos=

Optional. True or false. Defines if the broker should retain the messages sent to

it. Defaults to false.

#mqtt:.retain=
mqtt:broker.retain=true

Optional. True or false. Defines if messages are published asynchronously or

synchronously. Defaults to true.

#mqtt:.async=

Optional. Defines the last will and testament that is sent when this client goes offline

Format: topic:message:qos:retained

#mqtt:.lwt=

I dunno, but before i reinstalled openhab i’m not sure that if folder addons was empty. Now after reintall i have these files in addons folder:

org.openhab.action.mqtt-1.8.3.jar
org.openhab.binding.http-1.8.3.jar
org.openhab.binding.mqtt-1.8.3.jar
org.openhab.binding.ntp-1.8.3.jar
org.openhab.persistence.exec-1.8.3.jar
org.openhab.persistence.logging-1.8.3.jar
org.openhab.persistence.mqtt-1.8.3.jar
org.openhab.persistence.rrd4j-1.8.3.jar

These are the item and sitemap of my example:

item

Group All

Switch mqttsw1 “Switch 1” (all) {mqtt=">[broker:/testsw/1:command:on:1],>[broker:/testsw/1:comma
nd:off:0]"}

Switch mqttsw2 “Switch 2” (all) {mqtt=">[broker:/testsw/2:command:off:0],>[broker:/testsw/2:comm
and:on:1]"}

Switch lamp1 “Office Lamp” (all){mqtt=">[broker:/casa/terraza/nodemcu1/p1/com:command:1:ON],>[br
oker:/casa/terraza/nodemcu1/p1/com:command:0:OFF],<[broker:/casa/terraza/nodemcu1/p1/state:state
:default]"}

sitemap

sitemap test1 label=“Main Menu”
{
Frame label=“MQTT” {
Switch item=mqttsw1 label="MQTT Switch 1"
Switch item=mqttsw2 label="MQTT Switch 2"
Switch item=lamp1 label=“Office Lamp”
}
}

And as you can see nothing is published in topic /casa/# when i switch on/off lamp1, but status appears in openhab log as you can see above.

mosquitto_sub -d -t /casa/#
Client mosqsub/6435-raspberryp sending CONNECT
Client mosqsub/6435-raspberryp received CONNACK
Client mosqsub/6435-raspberryp sending SUBSCRIBE (Mid: 1, Topic: /casa/#, QoS: 0)
Client mosqsub/6435-raspberryp received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/6435-raspberryp sending PINGREQ
Client mosqsub/6435-raspberryp received PINGRESP

thanks again.

Hi Again!!!

At the end all worked!!!

I saw that my code of item was wrong, i changed by one that i found:

http://www.esp8266.nu/index.php/Tutorial_OpenHAB_Switch

and now worked!!!

thanks for your time!