Help setting up MQTT with OH2 latest nightly

Hi,

I am trying to get MQTT running with a runtime from 2.10.2015 (timestamp of the jar files in runtime/server).

This is my conf/services/mqtt.cfg

localhost.url=tcp://127.0.0.1:1883

This is the address of my local mosquitto, which is hidden in my private network, so no passwords are configured. When starting the runtime, I get to the stage where the debug log shows

[DEBUG] [o.e.s.io.transport.mqtt.MqttService:118  ] - Starting MQTT Service...

from the MqttService class, but nothing more. This remains so even if I configure an item which wants to read from this broker.

On the other hand, if I try to use that broker from my own binding, when I call

registerMessageConsumer('owntracks/#', myconsumerobject)

i can see in my logs (I added a few logger.debug() statements) that the addConsumer method of the MqttBrokerConnection is called, but nothing more happens because the variable started is still false.

So, if anyone has already gotten MQTT working in a current OH2 runtime, I’d love some help :smile:

There’s nothing special really to configure for OH2.

Check you added binding.mqtt.jar as well as transport.mqtt.jar?

Would you mind sharing your configuration with me? As far as I understood binding configuration with OH2, I would need a conf/services/mqtt.cfg in which I define my broker:

hakan@openhab:~/conf$ cat services/mqtt.cfg 
broker.url=tcp://127.0.0.1:1883
broker.clientId=openhab

and possibly some items to use data from the broker:

hakan@openhab:~/conf$ cat items/mqtt.items 
Number Foo_Temp "Foo Temperature [%.1f °C]" <temperature> (Foo,Temperature) {mqtt="<[broker:openhab/foo/temperature:state:default]"}

all I get with further debugging information on my setup is that the MqttService.updated() method is called with no properties, which makes it return immediately and fail to start any consumers. This sounds like I need to set up something more somewhere, but I am totally out of ideas by now.

You never answered if you have the binding jar in the addons folder or not…

Here’s my cfg

mosquitto.url=tcp://192.168.0.254:1883

Here’s my item file

Switch 	bedroom_light_status 	"Bedroom Light Online [%s]"		(gAvailability) 		{mqtt="<[mosquitto:dev/18fe34a15b69/status:state:MAP(mqtt.map)]"}

Sorry about the binding question. Yes, I do have my own binding in the addons directory. It also gets initialized just fine, I can use its discovery and see it does work. What I am trying to get working is using the mqttService from it.

So, after banging my head against the code and log files yesterday I decided to set up a simple item to see whether the mqtt part of OH2 itself is working or whether I have some problem with my configuration.

@Kai , do you have any insight you could share?

Hmmmm, are you using some kind of custom MQTT addon? Is it maybe overriding something? Is the official MQTT binding working for you like it does on mine?

Stupid question, in what file did you put this bit of configuration? conf/services/mqtt.cfg or somewhere else? I am getting pretty desperate for ideas by now :blush:

config:
/opt/openhab2/conf/services/mqtt.cfg

items:
/opt/openhab2/conf/items/demo.items

SUCCESS !!!1!!1!1!!einself!1!

My development OH2 instance just successfully pushed an item value change to the mosquitto server :fireworks: :grinning:

In the end, it was a simple wrong assumption on my part. I saw the mqtt binding in the Eclipse repository and assumed incorrectly that it would already be working. Especially given that the 2.0.0-SNAPSHOT builds contain some 1.8.0 jars but no mqtt ones.

In the end, @kai told me that MQTT in ESH is not functional yet and that I should take the relevant jars from the 1.8.0-SNAPSHOT build. Taking the following jars from the latest Jenkins build of 1.8.0-SNAPSHOT:

org.openhab.binding.mqtt-1.8.0-SNAPSHOT.jar
org.openhab.io.transport.mqtt_1.8.0.201510250300.jar
org.openhab.persistence.mqtt-1.8.0-SNAPSHOT.jar

and setting up conf/services/mqtt.cfg as mentioned in one of my previous postings in this thread gave me a working MQTT setup.

Thanks again everyone, and a big “sorry” to @danielwalters86 that I did not get your hint that I needed the three jars.

2 Likes

Hi @hakan,

thanks for the hint - I am struggling with the same brain hick-up :wink:

@hakan

I don’t see this file in my OH1 installation (and owntracks / mosquitto works fine).
I just have:

org.openhab.binding.mqtt-1.8.3.jar
org.openhab.binding.mqttitude-1.8.3.jar
org.openhab.persistence.mqtt-1.8.3.jar