MQTT Binding not working - I'm getting crazy here

Hey guys,

I’m probably missing an important piece here, but for some reason my mqtt binding does not work . and I’m getting crazy!

Information:

  • OpenHab 1.83 (installed manually - no apt-get)
  • mqtt plugin in addons directory
  • Mosquitto runs fine… I can pub and sub from every machine.

openhab.cfg:

mqtt:piq.url=tcp://192.168.1.111:1883
mqtt:piq.clientId=piq
mqtt:piq.qos=0
mqtt:piq.async=false
mqtt:piq.retain=false

Item - Config:

Inbound:

Switch Presence_Test "Presence Test [%s]" {mqtt="<[piq:presence/test:state:default]"}

Outbound:

String TestOut TestOut" {mqtt=">[piq:test/myTest:state:*:default]"}

=> Inbound should receive commands (ON/OFF) and Outbound should send String to the queue.

Rule for outbound:

TestOut.postUpdate("test2134")

Log file:

11:42:41.192 [DEBUG] [.io.transport.mqtt.MqttService:123  ] - Starting MQTT Service...
11:42:41.273 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl:53   ] - Service Discovery initialization completed.
11:42:41.286 [INFO ] [.io.transport.mqtt.MqttService:108  ] - MQTT Service initialization completed.
11:42:41.288 [INFO ] [o.i.t.m.i.MqttBrokerConnection:114  ] - Starting MQTT broker connection 'piq'
11:42:41.295 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:294  ] - Creating new client for 'tcp://192.168.1.111:1883' using id 'piq' and file store '/tmp/piq'
[...]
11:42:43.960 [DEBUG] [io.rest.internal.RESTActivator:33   ] - REST API has been started.

Unfortunately no interaction with mosquitto.

What am I missing???

Thanks very much in advance,

Sascha

Maybe the Problem ist postUpdate?

see http://stackoverflow.com/questions/28981946/what-is-the-difference-between-postupdate-and-sendcommand-in-openhab

postUpdate just changes the item to the new value, but no action is performed.

Try TestOut.sendCommand("test1234") should perform the action and publish to your MQTT Broker.

Andreas

Hey Andreas,

thanks for the hint. I’ll try that later.

Unfortunately that does not explain why incoming messages are not retrieved!

Btw: I’ve also seen that other users have much more mqtt debugging output For some reasor I don’t.

Thanks!

Sascha

At home I have two sample items to test the MQTT system.
When I am at home I’ll send them:

  • subscribe to MQTT topic (String item; published by Android mobile phone)
  • publish MQTT Topic (Switch item; subscribed to by Android mobile phone)

Both is working without problems…

Andreas

When playing around with OH2 I had it working as well… that’s one of the reason why it’s bugging me so much. :frowning:

When using sendCommand() I can see that the command is being retrieved by the item, but nothing is being sent to my queue…

So it looks like it’s a basic problem with the plugin… either not configured correctly or maybe some access issues.

It would be great if you could send me the files! According to the docs my Items should be correct, though.

I’ve also tested the configuration by adding a weird port value… and it looks like the mqtt binding reacts on that:

16:17:25.415 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:294  ] - Creating new client for 'tcp://192.168.1.111:118831' using id 'piq' and file store '/tmp/piq'
16:17:25.535 [ERROR] [.io.transport.mqtt.MqttService:114  ] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttException: MqttException
        at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:34) ~[na:na]
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:553) ~[na:na]
        at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_65]
Caused by: java.lang.IllegalArgumentException: port out of range:118831
        at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143) ~[na:1.8.0_65]
        at java.net.InetSocketAddress.<init>(InetSocketAddress.java:224) ~[na:1.8.0_65]
        at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:64) ~[na:na]
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:538) ~[na:na]
        ... 1 common frames omitted

I also get a timeout when I use a wrong host:

16:20:45.051 [ERROR] [.io.transport.mqtt.MqttService:114  ] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttException: MqttException
        at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:34) ~[na:na]
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:553) ~[na:na]
        at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_65]
Caused by: java.net.SocketTimeoutException: connect timed out

So the MQTT plugin is definitely triggered…

Greetz and thx,

Sascha

Here we are…

I’m on openHAB 1.8.1 and mqqt 1.8.2

openhab.cfg:

mqtt:mosquitto.url=tcp://openhab.zuhause.lan:1883
mqtt:mosquitto.clientId=openHAB
mqtt:mosquitto.user=username
mqtt:mosquitto.pwd=password
#mqtt:<broker>.qos=<qos>
#mqtt:<broker>.retain=<retain>
#mqtt:<broker>.async=<async>
#mqtt:<broker>.lwt=<last will definition>

Items:

Switch mqttSwitch      {mqtt="<[mosquitto:haus/mqtttest/light:state:MAP(MqttSwitch.map)],>[mosquitto:haus/mqtttest/light:command:ON:1],>[mosquitto:haus/mqtttest/light:command:OFF:0]"}
Number mqttSwitchState {mqtt="<[mosquitto:haus/mqtttest/light:state:default]"}
String mqttTextS4      {mqtt="<[mosquitto:haus/test/TextS4:state:default"}

Sitemap:

Switch item=mqttSwitch      label="MQTT Test Switch"
Text   item=mqttSwitchState label="MQTT Test Switch State [%d]"
Text   item=mqttTextS4      label="Text S4: [%s]"

If you change the mqttSwitch within the sitemap, the switch state changes within MQTT topic.
mqttSwitchState changes as well, because this one represents the state of the switch. This state is shown within the sitemap as text and cannot be change there.
The item mqttTextS4 shows the topic in the sitemap. If you change this string from another MQTT client, you can see this string within your sitemap…

Typo in your items file (unbalanced quotes). Try the openHAB Designer, or carefully scrutinize each and every line of your items file to look for syntax errors.

Hey watou,

I’ve seen that already and it’s fixed. I hoped that would fix everything, but that wasn’t the case. :frowning: All the items look syntactically correct.

Andreas, there’s also a typo in your item file, you’re missing a “]” here. :slight_smile:

{mqtt="<[mosquitto:haus/test/TextS4:state:default"}

I fixed that - and it just does not work. So crazy…

I will now strip down everything and just keep on simple item… just to see if that works!

Sascha