Binding with MQTT (Mosquitto) not working

I’m new to OpenHab and wanted to setup the most basic example with MQTT: I publish a message manually on a MQTT topic and want to display the messagevalue in the openhab webfrontend:

My setup

Hardware en software

I installed OpenHab v1.8.1 on a Raspberry Pi 3 and successfully setup a Mosquitto broker (v1.4.8). I can subscribe and publish messages on queus, also from external machines. In the openhab addons folder I placed org.openhab.binding.mqtt-1.8.1.jar


mqtt:localbroker.url=tcp:// mqtt:localbroker.retain=true
Group All Group gGroundFloor (All)

Group GF_Living “Living Room” (gGroundFloor)

String TestTemperature “Temperature [%s]” (GF_Living) {mqtt="<[localbroker:home/temperature:state:default]"}

sitemap default label="Garage" { Frame label="Temperature test" { Text item=TestTemperature } }
Output log openhab.log
17:11:51.328 [DEBUG] [.io.transport.mqtt.MqttService:123 ] - Starting MQTT Service... 17:11:51.403 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl:53 ] - Service Discovery initialization completed. 17:11:51.428 [INFO ] [.io.transport.mqtt.MqttService:108 ] - MQTT Service initialization completed. 17:11:51.430 [INFO ] [o.i.t.m.i.MqttBrokerConnection:114 ] - Starting MQTT broker connection 'localbroker' 17:11:51.455 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:294 ] - Creating new client for 'tcp://' using id 'openhab.1458490311450' and file store '/tmp/localbroker'
Trigger testcase
From a Linux machine I publish a message to the topic on the Raspberry Pi. I publish the String "9999" to the queue and treat it as a String in the default.items configurationfile. mosquitto_pub -t home/temperature -m "9999" -h

When I subscribe to this channel, I correctly receive this message. I subscribed for the channel as well on the pi as on my linuxmachine.

In a browser I open the webpage The sitemap is rendered correctly but the published value is never showed.

I think everything is well configured so I don’t understand why I can’t display the value from the MQTT channel.

I cannot find a problem.

The only difference to my config is that I am using a Number item instead of String.

Christoph, thx for your reply and checking your configuration. A minute ago I discovered the problem, although I don’t really understand the context.

I installed OpenHab via apt-get and everything was installed in /etc/openhab. So I added items, sitemaps and addons in this directorystructure. In other forumtopics I saw some people had some extra MQTT debug logentries that I didn’t have:

21:43:45.668 [DEBUG] [.b.mqtt.internal.MqttActivator:34 ] - MQTT binding has been started. 21:43:45.698 [DEBUG] [i.internal.GenericItemProvider:341 ] - Start processing binding configuration of Item 'TestTemperature (Type=StringItem, State=Uninitialized)' with 'MqttGenericBindingProvider' reader. 21:43:45.706 [DEBUG] [b.mqtt.internal.MqttItemConfig:72 ] - Loaded MQTT config for item 'TestTemperature' : 1 subscribers, 0 publishers 21:43:45.708 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:476 ] - Starting message consumer for broker 'localbroker' on topic '/home/temperature' 21:43:45.729 [DEBUG] [m.internal.MqttEventBusBinding:68 ] - MQTT: Activating event bus binding.

And then I discovered my filesystem contains the whole openhabdirectory also in /user/share/openhab but the addons directory was empty. So after I added org.openhab.binding.mqtt-1.8.1.jar to the addons directory and restarted openhab the whole setup worked.

I don’t understand how and why everything was copied to that usr/share directory (except the content of the addons folder).

apt-get installs openHAB to /usr/share/openhab. But that are only the static files, configs reside in /etc/openhab, logs under /var/log/openhab and so on - just the debian way of an installation.

I think you didn’t install the addons with apt-get, right? If you do apt-cache search openhab, you will find the whole bunch of openhab addons as single packets to install, and apt-get will install them at your order to the right folder :slight_smile:

1 Like

You are right Udo. The addons were installed by myself via wget in the addonsfolder in etc/openhab. I created this addons folder myself and that was a mistake due to missing insights in the unix filesystem …

Thank you for your explanation!