MQTT config under OH2

I have OH2 installed, the MQTT 1.9 binding installed, and OH1.x compatibilty = true.

Now, to configure/use the binding… Nothing showing under ‘Things’ in Paper UI.
Is it necessary to configure using a text file?
Do I configure this as an Item or a Thing, or both?

MQTT is running, and I can mosquitto_sub to the topics being published OK

The physical object is an ESP8266 with a DS18B20 temperature sensor, and a photocell on the analog input.
The intent is to read outside temperature and light levels, and to act on them ~ I’m in a wooded valley, and using (astro:sunset) to define “it’s getting dark” is proving too variable.

1 Like

As MQTT binding is version 1.9 it doesn’t support autoconfiguration of things and items. These have to be configured the “old way” in the items-file.

Found a config file in openhab 2. Under Conf/services there should be a mqtt file. I think it needs to be configured as regular 1.x bindings so there should be documentation for that

http://docs.openhab.org/tutorials/migration#configuration-and-folder-structure

> Instead of the global configurations/openhab.cfg file, there is now an individual file per add-on in conf/services. The <key>: prepended to each configuration property is removed in the new <key>.cfg files.

1 Like

I’ve configured my mqtt.cfg file to be as follows:

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
oh2.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.
oh2.clientId=OpenHAB2_MQTT

But in my mosquitto.log I see this:

1477129863: Client OpenHAB2 already connected, closing old connection.
1477129863: Client OpenHAB2 disconnected.
1477129863: New client connected from 192.168.5.3 as OpenHAB2 (c1, k60).
1477129873: New connection from 127.0.0.1 on port 1883.

Where is it getting the client ID of OpenHAB2 from? I’ve just uninstalled, deleted the mqtt*.cfg files and reinstalled the mqtt binding through PaperUI with the same output. I’m using OH2 Beta4 on the Pi

Is this only on restart or happens periodically while running?

I’m still getting that error where the connection is reset.
21:10:26.149 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost

Looks like yours may just be a timeout. Can you post more of the log?

Thanks!

It’s happening while running, every ten seconds in fact!

/var/log/openhab2/openhab.log

2016-10-25 08:21:39.904 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection '<broker>'
2016-10-25 08:21:39.924 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost
Connection lost (32109) - java.io.EOFException
        at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:138)[202:org.openhab.io.transport.mqtt:1.9.0.b4]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]
Caused by: java.io.EOFException
        at java.io.DataInputStream.readByte(DataInputStream.java:267)[:1.8.0_65]
        at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:56)[202:org.openhab.io.transport.mqtt:1.9.0.b4]
        at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:100)[202:org.openhab.io.transport.mqtt:1.9.0.b4]
        ... 1 more
2016-10-25 08:21:39.929 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'broker' was lost: Connection lost : ReasonCode 32109 : Cause : null
2016-10-25 08:21:39.931 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'broker'

/var/log/mosquitto/mosquitto.log

1477383800: New connection from 192.168.5.3 on port 1883.
1477383800: Client OpenHAB2 already connected, closing old connection.
1477383800: Client OpenHAB2 disconnected.
1477383800: New client connected from 192.168.5.3 as OpenHAB2 (c1, k60).
1477383810: New connection from 127.0.0.1 on port 1883.
1477383810: Client OpenHAB2 already connected, closing old connection.
1477383810: Client OpenHAB2 disconnected.
1477383810: New client connected from 127.0.0.1 as OpenHAB2 (c1, k60).
1477383820: New connection from 192.168.5.3 on port 1883.
1477383820: Client OpenHAB2 already connected, closing old connection.
1477383820: Client OpenHAB2 disconnected.
1477383820: New client connected from 192.168.5.3 as OpenHAB2 (c1, k60).

I have an idea that the configuration for 1.x bindings that’s possible from the Paper UI is not coexisting properly with the contents of the <service>.cfg file. Any chance you have more MQTT configuration via the UI or other .cfg files?

1 Like

@Rob_Pope I had a similar problem in the past… It was due to OpenHab 2 loading up the default mqtt.cfg config file (with the sample <broker> name)… it was my mistake since I removed the comments from the lines without adjusting the broker name… After I fixed the mistake, the <broker> info still remained (as a second broker) in OH2 “internal database” (I don’t know how to call it :)) and was causing errors because all other parameters for <broker> were null.

Try to check with the Karaf Console (ssh openhab@localhost -p 8101 with password: habopen) what has been already stored in the OH2 “internal database” by using:

config:edit org.openhab.mqtt
config:property-list

Also, you can use: config:list to show you all bindings configs stored.

You can start clean by configuring your mqtt.cfg and mqtt-eventbus.cfg and clearing out whatever is stored already by:
config:delete org.openhab.mqtt and then restarting OH2 to reload the .cfg files

BR,
Dim

16 Likes

Thanks for your response @Dim - It turns out the internal database had three configurations in there. A delete and restart of OH2 fixed the issue for me.

Thanks again!

1 Like

Great stuff, have not found that yet. Do you have any link available where we can find that? Thx.

Looks like that was probably my issue but I refreshed my OH installation (“lost” settings) so my problem went away after that!

Glad someone else knew the real issue!

Is there a ticket logged (or should there be) for using the configuration in the .cfg to overwrite configuration information stored in mapdb?

1 Like

Hi @sihui,

I found this kind of info from reading various posts here in the community and mainly from this great thread:

I also read a bit the Apache Karaf Shell wiki here: https://karaf.apache.org/manual/latest/#_shell_console_basics

but mostly… trial and error :slight_smile:

BR,
Dim
Ps: @jflarente: That’s a big discussion… check out the thread referenced above. I believe that the short answer is no because this is by design.

1 Like

:grin:
Thx a lot.

@Dim, would you be willing to write this posting up as a quick tutorial as a top level thread under Tutorials and Examples? I think this really important and not well known and it actually answers a lot of questions I had. Eventually I can see this migrating to the official docs.

Absolutely. I will give it a try and write some examples on how to “manage” configurations that are already stored within the OpenHab 2 OSGi cache. I am not an expert in Apache Karaf, so I will need help to “iron-out” any errors :slight_smile:

BR,
Dim

1 Like

If you see any of my or Thom’s tutorials you will see we all get lots of help on such postings. I look forward to reading it.

1 Like

@rlkoshak: First (alpha) version posted on:

:sunglasses:

1 Like

Please Help, I spent the day trying to debug.
I have run out of ides…

The best I can tell when I press the switch It triggers a event
2017-01-20 17:00:24.129 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ''
2017-01-20 17:02:56.931 [DEBUG] [inding.mqtt.internal.MqttItemBinding] - Publishing command ON to control/SW010101/command
But the broker does not see any <> messages from OH2:
1484950320: Sending CONNACK to paho-263225371366065 (0, 0)
1484950321: Received PUBLISH from paho-263225371366065 (d0, q0, r0, m0, ‘control/SW010101/command’, … (2 bytes))
1484950322: Received PUBLISH from WallSwitch001 (d0, q0, r0, m0, ‘control/SW010101/SW1/state’, … (1 bytes))
1484950330: Received PINGREQ from Openhab2
1484950330: Sending PINGRESP to Openhab2

the broker does see Openhab:
1484950210: Sending CONNACK to Openhab2 (0, 0)
1484950217: Received PINGREQ from WallSwitch001