MQTT on OH2 - help needed

Hello,

As an OH newbee, for me it seems rather painful to configure the MQTT binding on OH2.
What I did for a small sample:

  1. Installed OH2 snapshot 2.0.0

2: sidemap

sitemap actor label=“menue”
{
Frame {
Group item=gAct1 label=“Actor 1” icon=“Actor 1”
}
}

  1. items

// Gruppen
Group gAct1 // Gruppe Actor 1

/MQTT/
Switch LED11 “LED11” (gAct1) { mqtt=">[mosquitto:actor1/ch0:command:ON:ch0_255],>[mosquitto:actor1/ch0:command:OFF:ch0_0]" }
Switch LED12 “LED12” (gAct1) { mqtt=">[mosquitto:actor1/ch1:command:ON:ch1_255],>[mosquitto:actor1/ch1:command:OFF:ch1_0]" }
Switch LED13 “LED13” (gAct1) { mqtt=">[mosquitto:actor1/ch2:command:ON:ch2_255],>[mosquitto:actor1/ch2:command:OFF:ch2_0]" }
Switch LED14 “LED14” (gAct1) { mqtt=">[mosquitto:actor1/ch3:command:ON:ch3_255],>[mosquitto:actor1/ch3:command:OFF:ch3_0]" }

  1. Bindings in addons
    action.mqtt.1.8.3
    binding.mqtt.1.8.3 // I tried 1.9.0.b2 too

  2. services\runtime.conf
    mqtt:mosquitto.url=tcp://localhost:1883

6.services\addon.conf
package = standard
remote = true
legacy = true
binding = mqtt
ui = basic,paper
persistence = influxdb,rrd4j,mapdb
action = nma,mail
transformation = xslt,map,regex,javascript

As result, OH2 generates the nice ui, but if I toggle the switches, no MQTT messages are sent out.

I have implemented the same sample on OH1, this works perfectly.
Meanwhile I have read a lot of documentation and hints, but the more I read, the more confused am I.

Many thanks for your help and best regards
Walter

Hi @waltert,

Let’s validate a couple of things (step by step) to get this working.

First of all: Check if the binding is correctly installed and up & running:

Try not to use manual installation methods but rather use Paper UI for installing bindings.

  • Remove the .jar mqtt binding files from /usr/share/openhab2/addons/
  • Install MQTT (binding-mqtt1) from Paper UI
  • Use mqtt1 (not mqtt) for the binding= name in your /etc/openhab2/services/addons.cfg (since MQTT is still a 1.x binding)
  • Fix your /etc/openhab2/services/mqtt.cfg (not runtime.conf) file to contain something like:
mosquitto.url=tcp://localhost:1883
mosquitto.clientId=openhab
mosquitto.qos=0
mosquitto.retain=false
mosquitto.async=true

and post some log output from /var/log/openhab2/openhab.log related to MQTT.

You can enable DEBUG level of logging for this binding from the Karaf Console (ssh openhab@localhost -p 8101 with password habopen) by:

log:set DEBUG org.openhab.binding.mqtt

Ps: A lot of the MQTT binding info that you will find online refer to OH1. There are some differences in OH2. These are explained here: http://docs.openhab.org/tutorials/migration.html

Hi Dim,

Many thanks for your quick help.

I did, as you suggested.
Because my paperui (on windows 7) was empty (?), I have used the karaf console in order
to install mqtt binding and io-transport with feature:install. The log looks not bad now:

21:18:49.705 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at /start
21:18:49.737 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
21:18:49.955 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.

21:18:49.955 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosqu
itto’
21:18:52.089 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
21:18:59.190 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘LED11’ received command ON

All green, no error! But it did NOT generate mqtt publications.
Any idea?

Again many thanks
Walter

Now for the next step: Check if the Mosquitto broker is getting the messages (when you press the switch on your sitemap by subscribing to all topics under actor1:

mosquitto_sub -t actor1/#

You could use any MQTT client also (like mqttlens) to subscribe to this topic also to check.

Check also the DEBUG logs of the MQTT binding for any errors/messages

Hi Dim,

Many thanks again for your reply.

I have attached the Mosquitto-log:

C:\Mosquitto>mosquitto -v
1484991929: mosquitto version 1.4.10 (build date 24/08/2016 21:03:24.73) starting
1484991929: Using default config.
1484991929: Opening ipv6 listen socket on port 1883.
1484991929: Opening ipv4 listen socket on port 1883.
1484991989: New connection from 127.0.0.1 on port 1883.
1484991989: New client connected from 127.0.0.1 as openhab (c1, k60).
1484991989: Sending CONNACK to openhab (0, 0)
1484992049: Received PINGREQ from openhab
1484992049: Sending PINGRESP to openhab
1484992052: New connection from ::1 on port 1883.
1484992052: New client connected from ::1 as mosqsub/2480-Walter-MCU (c1, k60).
1484992052: Sending CONNACK to mosqsub/2480-Walter-MCU (0, 0)
1484992052: Received SUBSCRIBE from mosqsub/2480-Walter-MCU
1484992052: # (QoS 0)
1484992052: mosqsub/2480-Walter-MCU 0 #
1484992052: Sending SUBACK to mosqsub/2480-Walter-MCU
1484992109: Received PINGREQ from openhab
1484992109: Sending PINGRESP to openhab
1484992112: Received PINGREQ from mosqsub/2480-Walter-MCU
1484992112: Sending PINGRESP to mosqsub/2480-Walter-MCU

OH logs in and no publications have been sent after toggeling some switches. No subscribes arrived.

C:\Mosquitto>mosquitto_sub -t “#”

^C

Could something be wrong with the mqtt-comand in the item?

Best regards
Walter

Let’s check:

Switch LED11 "LED11" (gAct1) { mqtt=">[mosquitto:actor1/ch0:command:ON:ch0_255],>[mosquitto:actor1/ch0:command:OFF:ch0_0]" }

It seems to be correctly formatted…

Try (for testing) a slightly simpler version (without transformations) just to see if the messages reach MQTT:

Switch LED11 "LED11" (gAct1) { mqtt=">[mosquitto:actor1/ch0:command:ON],>[mosquitto:actor1/ch0:command:OFF]" }

Sorry, no change.

I have read somewhere in the forum from “openhab-transport-mqtt”.
But I could not install it with feature:install => no entry

Do you know what this is and if it is necessary, how to install it?

Best regards
Walter

I don’t think that this is necessary.

In my OH2 system i have only openhab-binding-mqtt1 installed (and started)

openhab> feature:list | grep MQ
esh-tp-paho                               | 0.9.0.b4         |          | Uninstalled | distro-2.0.0-SNAPSHOT   | MQTT v3 Client
openhab-transport-mqtt                    | 2.0.0            |          | Uninstalled | distro-2.0.0-SNAPSHOT   | MQTT Transport
openhab-action-mqtt                       | 1.9.0            |          | Uninstalled | addons-2.0.0-SNAPSHOT   | MQTT Action
openhab-binding-mqtt1                     | 1.9.0            | x        | Started     | addons-2.0.0-SNAPSHOT   | MQTT Binding
openhab-binding-mqttitude1                | 1.9.0            |          | Uninstalled | addons-2.0.0-SNAPSHOT   | OwnTracks (formerly MQTTitude) Binding
openhab-persistence-mqtt                  | 1.9.0            |          | Uninstalled | addons-2.0.0-SNAPSHOT   | MQTT Persistence

On the other hand, if I see the following in the bundles:

openhab> bundle:list |grep MQ
193 | Active   |  80 | 1.9.0                 | openHAB MQTT Binding
198 | Active   |  80 | 1.9.0                 | openHAB MQTT Transport Bundle

I believe that the Transport binding is used as a shared mechanism for other bindings to use the MQTT protocol.

For regular items, you only need the standard mqtt1 binding.

I would try to fix the Paper UI and install MQTT binding again from there… You wrote that your Paper UI shows nothing?

I have the same bundles installed:

openhab> feature:list | grep MQ
esh-tp-paho | 0.9.0.SNAPSHOT | | Uninstalled | distro-2.0.0
-SNAPSHOT | MQTT v3 Client
openhab-transport-mqtt | 2.0.0.SNAPSHOT | | Uninstalled | distro-2.0.0
-SNAPSHOT | MQTT Transport
openhab-action-mqtt | 1.9.0.SNAPSHOT | | Uninstalled | addons-2.0.0
-SNAPSHOT | MQTT Action
openhab-binding-mqtt1 | 1.9.0.SNAPSHOT | x | Started | addons-2.0.0
-SNAPSHOT | MQTT Binding
openhab-binding-mqttitude1 | 1.9.0.SNAPSHOT | | Uninstalled | addons-2.0.0
-SNAPSHOT | OwnTracks (formerly MQTTitude) Binding
openhab-persistence-mqtt | 1.9.0.SNAPSHOT | | Uninstalled | addons-2.0.0
-SNAPSHOT | MQTT Persistence

openhab> bundle:list | grep MQ
220 | Active | 80 | 1.9.0.201701200211 | openHAB MQTT Binding
221 | Active | 80 | 1.9.0.201701200211 | openHAB MQTT Transport Bundle
openhab>

Yes, my paperui is empty.

What do do with openhab-addons…kar?
It is now in my Openhab2.folder, I copied it into the addon-folder, but no effect.

Best regards
walter

If you donwloaded openhab-addons-2.0.0.RC1.kar and placed it in your /usr/share/openhab2/addons folder, you should have all you need.

I don’t like that your Paper UI is broken… something is not working with your OH2 installation…

Try enabling DEBUG on the mqtt binding in Karaf:

log:set DEBUG org.openhab.binding.mqtt

and check/post the logs from /var/log/openhab2/openhab.log

Should be

log:set DEBUG org.openhab.binding.mqtt

mqtt1 is part of the feature name, not the logger/package name.

1 Like

I got the following messages in the openhab.log:

2017-01-21 17:15:39.705 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2017-01-21 17:15:39.752 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-01-21 17:15:39.752 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto’
2017-01-21 17:15:41.342 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2017-01-21 17:15:41.352 [DEBUG] [org.openhab.binding.mqtt ] - BundleEvent STARTING - org.openhab.binding.mqtt
2017-01-21 17:15:41.354 [DEBUG] [.binding.mqtt.internal.MqttActivator] - MQTT binding has been started.
2017-01-21 17:15:41.393 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - MQTT: Activating event bus binding.
2017-01-21 17:15:41.393 [DEBUG] [org.openhab.binding.mqtt ] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler, org.osgi.service.cm.ManagedService}={event.topics=openhab/, service.pid=org.openhab.mqtt-eventbus, component.name=org.openhab.binding.mqtt.eventbus, component.id=169, service.id=302, service.bundleid=220, service.scope=bundle} - org.openhab.binding.mqtt
2017-01-21 17:15:41.394 [DEBUG] [org.openhab.binding.mqtt ] - ServiceEvent REGISTERED - {org.openhab.model.item.binding.BindingConfigReader, org.openhab.binding.mqtt.MqttBindingProvider}={component.name=org.openhab.binding.mqtt.genericbindingprovider, component.id=170, service.id=303, service.bundleid=220, service.scope=bundle} - org.openhab.binding.mqtt
2017-01-21 17:15:41.397 [DEBUG] [org.openhab.binding.mqtt ] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler}={event.topics=openhab/
, component.name=org.openhab.binding.mqtt.MqttItemBinding, component.id=168, service.id=304, service.bundleid=220, service.scope=bundle} - org.openhab.binding.mqtt
2017-01-21 17:15:41.400 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - Initializing MQTT Event Bus Binding
2017-01-21 17:15:41.400 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - MQTT Event Bus Binding initialization completed.
2017-01-21 17:15:41.407 [DEBUG] [org.openhab.binding.mqtt ] - BundleEvent STARTED - org.openhab.binding.mqtt
2017-01-21 17:15:41.788 [INFO ] [assic.internal.servlet.WebAppServlet] - Started Classic UI at /classicui/app

Perhaps you can see something.

Best regards
Walter

After a reinstallation of Java and the new release of openHAB2 all works fine!!!
Even the paperui is filled with the addons.

Many thanks to Dim for his splendid support.

Best regards
Walter

1 Like