MQTT addon get no updates from broker

Hey,
I use openhab 1.8.1 at my raspberry pi and try to use the mqtt binding, placed at the addon dir.
At the same raspberry a mosquitto mqtt broker is running. I’ve tested this server a several time with different tools (mosquitto_pub, mosquitto_sub, MQTT.fx…) everything is working fine.

openhab.cfg
mqtt:localbroker.url=tcp://localhost:1883

default.items
Group Mqtt (All) String RaspyTemp "Raspberry CPU Temperature" <temperature> (Mqtt) {mqtt="<[localbroker:temp:state:default]"}

default.sitemap
Frame label="MQTT" { Text label="MQTT Raspi CPU Temp" { Frame { Text item=RaspyTemp } } }

Then I try to push messages like mosquitto_pub -t temp -m "1234". But the frontend of my openhab server is not responding. It shows an empty string.

This is, a smal log grep

cat logs/openhab.log | grep -i "mqtt" 2016-02-07 14:25:35.214 [DEBUG] [.io.transport.mqtt.MqttService] - Starting MQTT Service... 2016-02-07 14:25:35.363 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed. 2016-02-07 14:25:35.366 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'localbroker' 2016-02-07 14:25:35.423 [DEBUG] [o.i.t.m.i.MqttBrokerConnection] - Creating new client for 'tcp://localhost:1883' using id 'root.1454937935412' and file store '/tmp/localbroker' 2016-02-07 14:26:26.087 [DEBUG] [.b.mqtt.internal.MqttActivator] - MQTT binding has been started. 2016-02-07 14:26:26.249 [DEBUG] [i.internal.GenericItemProvider] - Start processing binding configuration of Item 'RaspyTemp (Type=StringItem, State=Uninitialized)' with 'MqttGenericBindingProvider' reader. 2016-02-07 14:26:26.268 [DEBUG] [b.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item 'RaspyTemp' : 1 subscribers, 0 publishers 2016-02-07 14:26:26.271 [DEBUG] [o.i.t.m.i.MqttBrokerConnection] - Starting message consumer for broker 'localbroker' on topic 'temp' 2016-02-07 14:26:26.357 [DEBUG] [m.internal.MqttEventBusBinding] - MQTT: Activating event bus binding.

Don’t know what I do wrong.

I don’t believe your MQTT topics are matched correctly. If the OH item is subscribed to “test/temperature”, you need to publish your topic to “-t test/temperature”.

I’m sorry. That was a litte copy-paste mistake in my post. I fixed that. The correct item code is {mqtt="<[localbroker:temp:state:default]"}

1 Like

try this:

 {mqtt="<[localbroker:/temp:state:default]"}

I tried this. Also I tried
mosquitto_pub -t /temp -m "1234"

No success :frowning:

Now I’ve made a whole new configuration

  • Ubuntu desktop pc
  • Java 1.8
  • Fresh openhab 1.8.1 installation (apt-get install openhab-runtime && apt-get install openhab-addon-binding-mqtt)
  • ONLY with following changes:

openhab.cfg
mqtt:mosquitto.url=tcp://test.mosquitto.org:1883

default.items
String temperature {mqtt="<[mosquitto:temp/random:state:default]"}

default.sitemap
sitemap default label="mqtt test" {
Frame label="Demo" {
Text item=temperature
}
}

To publish messages i use the official mosquitto test server (as above in openhab.cfg) and MQTT.FX.
This is a very simple and reproducible example. Why it won’t work?

Should I open an issue?

It’s odd that you are seeing the event bus binding start, but the openhab.cfg you provided does not have that configured.

Also, have you tried mosquitto_sub to make sure your mosquitto_pub commands are making it to the broker?

Lastly, is mosquitto set to listen for connections on localhost, and does localhost resolve to the loopback address 127.0.0.1? I assume you are running openHAB and mosquitto on the same machine?

Also, have you tried mosquitto_sub to make sure your mosquitto_pub commands are making it to the broker?

Yes, I subscribed the topic via mosquitto_sub. On the local machine as well as on an other machine. Also I used mqtt.fx. Both working fine and show my messages.

Lastly, is mosquitto set to listen for connections on localhost, and does localhost resolve to the loopback address 127.0.0.1? I assume you are running openHAB and mosquitto on the same machine?

For the system in my first post: yes. Mosqitto and openHAB are running on the same machine. Since it works with mosquitto_sub, I suppose mosquitto settings are right. Loopback address is set. But I also tried 127.0.0.1 at openhab.cfg.
Please also read my last post. I build a whole new system. Stripped down to a simple mqtt sample with an external mosquitto server. Even that does not work.

Your item is missing a label, including missing within the label a placeholder. Here is a replacement to try:

Number temperature "temperature [%.1f]" { mqtt="<[mosquitto:temp/random:state:default]" }
1 Like

OMG… now it works. I was to blind to see that.
Thank you very much.

I took this line from the openHAB wiki

Number temperature {mqtt="<[publicweatherservice:/london-city/temperature:state:default]"}

Perhabs this is an misleadingly sample.

Just changed the wiki to include example labels. Thanks for the suggestion!

1 Like