[Solved] MQTT2 setup on OH2

Tags: #<Tag:0x00007f2fbc68f158> #<Tag:0x00007f2fbc68eed8>

Hi,

I’m having problems on MQTT2 binding with my OH2 and raspberry.

I have installed the MQTT broker and succesfully connected to it with the Bridge (in things file). Also, created items but when I try to publish a messages with MQTT.fx, I’m not getting any info on OH2 logs. However, via ssh and “mosquitto_sub”-command I can see the messages.

I would really appreciate if somebody would help me.

Here are my config files:

mqttConnections.things:

Bridge mqtt:broker:myUnsecureBroker [ host=“127.0.0.1”, port=1883, secure=“OFF”, username=“openhabian”, password=“openhabian”, clientid=“openhabTest” ]
{
Thing topic mything {
Channels:
Type switch : lamp “Kitchen Lamp” [ stateTopic=“lamp/enabled”, commandTopic=“lamp/enabled/set” ]
Type string : alarmpanel “Alarm system” [ stateTopic=“alarmpanel/state”, commandTopic=“alarmpanel/set” ]
}
}

mqttTest.items:

String testMqttString “test Mqtt String” { channel=“mqtt:topic:myUnsecureBroker:mything:alarmpanel” }
Switch Kitchen_Light “Kitchen Light” { channel=“mqtt:topic:myUnsecureBroker:mything:lamp” }

Some of my logs:

[me.event.ThingUpdatedEvent] - Thing ‘mqtt:broker:myUnsecureBroker’ has been updated.
[hingStatusInfoChangedEvent] - ‘mqtt:broker:myUnsecureBroker’ changed from OFFLINE to ONLINE
[.ItemChannelLinkAddedEvent] - Link ‘testMqttString-mqtt:topic:myUnsecureBroker:mything:alarmpanel’ has been added.
[.ItemChannelLinkAddedEvent] - Link ‘Kitchen_Light-mqtt:topic:myUnsecureBroker:mything:lamp’ has been added.

When I try to publish a messages with MQTT.fx I cannot see the messages in the log. I have tried to use following topics:
/myUnsecureBroker/mything/alarmpanel/state/
/myUnsecureBroker/mything/alarmpanel/set/
/myUnsecureBroker/mything/alarmpanel/

In MQTT.fx subscribe I can see the messages.

What I’m doing wrong?

Please use the code fences

There you go. Hopefully the code is now more readable?

You stateTopic for the alarm panel: alarmpanel/state

The topic your tried: /myUnsecureBroker/mything/alarmpanel/state/

Notice the difference:

From MQTT.fx, on the topic: alarmpanel/state publish the payload ON

What happens?

@vzorglub I noticed a few missing “:” and the channel name was odd. Should the Thing and Item file be more like below?

Bridge mqtt:broker:myUnsecureBroker [ host=“127.0.0.1”, port=1883, secure=“OFF”, username=“openhabian”, password=“openhabian”, clientid=“openhabTest” ]
{
Thing mqtt:topic:mything {
Channels:
Type switch : lamp “Kitchen Lamp” [ stateTopic=“lamp/enabled”, commandTopic=“lamp/enabled/set” ]
Type string : alarmpanel “Alarm system” [ stateTopic=“alarmpanel/state”, commandTopic=“alarmpanel/set” ]
}
}
String testMqttString “test Mqtt String” { channel=“mqtt:topic:mything:alarmpanel” }
Switch Kitchen_Light “Kitchen Light” { channel=“mqtt:topic:mything:lamp” }

Unfortunately nothing happens =/

Hi H102,

I believe that thing name and the syntax is ok, I followed this guide:
https://www.openhab.org/addons/bindings/mqtt.generic/

Just asking b/c I was comparing what’s above to other mqtt 2.x config post on the forum and noticed a difference. I haven’t started moving all my mqtt items over to 2.x yet but shouldn’t be much longer before I take the plunge.:smile:

Best of luck and hope you get it working soon.:crossed_fingers:

Thanks and hopefully you succeed moving items to mqtt 2.x, maybe you can help me more then =) I will try to look around the other posts of mqtt 2.x related subjects.

Maybe the best workaround would be if somebody would post a simple working mqtt 2.x config files (.things and .items) for one item and tell in which topic should be published.

I appreciate all the help!

GOT IT WORKING! Just had to reboot the raspberry! =D And of course publish to the topic vincent suggested alarmpanel/state …so many hours just wasted.
Anyway, many thanks for helping me.

Next time I reboot the raspberry before asking help=)

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [ 
  host="192.168.0.34",
  secure=false,
  port=1883,
  qos=0,
  retain=false,
  clientid="Oh2Mqtt2Thing",
  //certificate="",
  //certificatepin=false,
  //publickey="",
  //publickeypin=false,
  keep_alive_time=30000,
  reconnect_time=60000,
  //lastwill_message="",
  //lastwill_qos=1,
  //lastwill_topic="",
  username="username",
  password="password"
]
{
    Thing topic PorchThermostat "Porch Thermostat" {
        Channels:
            Type switch : Mode "Mode" [
                stateTopic="House/Porch/Thermostat/Mode",
                commandTopic="House/Porch/Thermostat/Mode",
            ]
    }
}

Thanks Vincent, I will take a look your code and learn from the master to make the mqtt configuration more advanced=)