MQTT not working after upgrade to 1.8

Hi,

I have copied my configuration files from 1.7.1 to 1.8.0.

When using 1.8 MQTT does not receive any updates.

Here is the log files.

2016-01-13 20:15:40.203 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mqttbroker’
2016-01-13 20:15:40.308 [ERROR] [.io.transport.mqtt.MqttService] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttPersistenceException: MqttException
at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:76) ~[na:na]
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.(MqttAsyncClient.java:273) ~[na:na]
at org.eclipse.paho.client.mqttv3.MqttClient.(MqttClient.java:222) ~[na:na]
at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.openConnection(MqttBrokerConnection.java:297) ~[na:na]
at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.start(MqttBrokerConnection.java:115) ~[na:na]
at org.openhab.io.transport.mqtt.MqttService.updated(MqttService.java:112) ~[na:na]
at org.eclipse.equinox.internal.cm.ManagedServiceTracker$1.run(ManagedServiceTracker.java:183) [org.eclipse.equinox.cm_1.0.400.v20120522-1841.jar:na]
at org.eclipse.equinox.internal.cm.SerializedTaskQueue$1.run(SerializedTaskQueue.java:36) [org.eclipse.equinox.cm_1.0.400.v20120522-1841.jar:na]

Is the broker running at the mqttbroker configuration settings in openhab.cfg? Can you use mosquitto_sub at a command line to attempt to connect the same way?

This is from openhab.cfg. Is caps an issue?

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mqtt:MQTTbroker.url=tcp://192.168.0.9:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mqtt:MQTTbroker.clientId=openHAB

I get data when i use: mosquitto_sub -h 192.168.0.9 -t /#

I changed MQTTbroker to mqttbroker, and that did not work.

Then i changed it to mqttpi and now it starts without the exception and i get data in my items.

I have a different problem after upgrading from 1.7 to 1.8: all my contacts items stopped working. I realized the Contact items using the MQTT binding would not accept the “command” type anymore.

So Contact myContactItem {mqtt="<[myBroker:/topic/sub_topic:command:default]} does not work in 1.8 (it was working in 1.7). But Contact myContactItem {mqtt="<[myBroker:/topic/sub_topic:state:default]} still works…

Note the problem only happens with Contact items (default = OPEN / CLOSED) while Switch items (default = ON / OFF) still work OK.

Is it a regression?

I am pretty sure it’s a result of my code change, but I believe it was incorrect to be able to send commands to Contact items in the first place. The code for Contact items does not accept any command to be sent to them, but the reason it probably worked was a side effect of the previous code that ended up changing their state due to auto-update logic. (To test my theory, the items would probably not update if you use the Contact items under the 1.7.* MQTT binding but add , autoupdate="false" to the { binding section }.)

The reason it works with Switch items is because it is permitted (obviously) to send Switches commands, as the Switch item code shows.

The better approach is to change your MQTT binding strings for updating Contact items to update their state, not send them commands, so it conforms to the rules for item commands and states.

Hello Watou and thanks for your complete answer. OK I’ll change my code from “command” to “state” then.

1 Like

@watou, any chance you could help me get my contact properly updating in OH2?

This is my item, but it just doesn’t seem to update…

Contact Garage01Contact “Garage1” (AllItems, LogRRD4J) {mqtt="<[mosquitto:homie/d406c6e0/garagesensor/open:state:open:true],<[mosquitto:homie/d406c6e0/garagesensor/open:state:closed:false]"}

This is the full detail of my struggles…

Hmmm okay change the case seems to have fixed it…

Contact Garage01Contact “Garage1” (AllItems, LogRRD4J) {mqtt="<[mosquitto:homie/d406c6e0/garagesensor/open:state:OPEN:true],<[mosquitto:homie/d406c6e0/garagesensor/open:state:CLOSED:false]"}