Problems migrating MQTT 1 to MQTT 2 Binding

Hi,

I haven’t switched from MQTT 1 to MQTT 2 quite voluntarily yet and I’m pressed for time until noon tomorrow. I am using Ubuntu 18.04 and openHAB 2.5.12-1. So it all started when the bindings could not be installed again after restarting openHAB:

[ERROR] [.core.karaf.internal.FeatureInstaller] - Failed installing

If one searches for the error, it is suggested accordingly that one deletes in /var/lib/openhab2/config/org/openhab/addons.config. But this did not help. Also deleting the cache and tmp folders in /var/lib/openhab2/cache and /var/lib/openhab2/tmp. What really helped was reinstall the openhab-addons with sudo apt install --reinstall openhab2-addons.

What I miss after that is that I can use the legacy bindings even though it is enabled accordingly via PaperUI. Consequently, I can no longer use MQTT 1.

**cat /var/lib/openhab2/config/org/openhab/addons.config**
:org.apache.felix.configadmin.revision:=L"64"
action="mqtt,mail"
binding="astro,openweathermap,mqtt1,hue,digitalstrom,homematic,http1,kodi,miele,neato,netatmo,sonos,wemo,zwave,zigbee,doorbird,weather1,systeminfo,systeminfo1,exec,exec1,mail,somfytahoma,amazonechocontrol,mqtt"
legacy="true"
misc=",openhabcloud"
package="expert"
persistence=",jdbc-mariadb"
remote="true"
service.pid="org.openhab.addons"
transformation="map,xslt,scale,xpath,jsonpath,exec,regex,javascript"
ui="dashboard,classic,basic,paper,habpanel,habmin,restdocs"

I now save the error message that all addons with 1 cannot be installed accordingly. With some bindings, the action would no longer be necessary, for example, because the MQTT 2 binding automatically brings the function with it. Restdocs has moved etc. Let’s ignore this for a while. The focus here should be on MQTT, because I use it to communicate from one system with several, and this is fundamentally important.

What I unfortunately had to reinstall is mosquitto. I copied the configuration file beforehand:

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

allow_anonymous true
#user openhabvm
#password_file /etc/mosquitto/openhabbroker

The conf.d folder is empty and currently no user and password are used. The Mosquitto Broker is started and uses the port 1883.

Then I go to the PaperUI and installed the MQTT Binding (binding-mqtt - 2.5.12). Remember: MQTT 1 can not be found because it is legay even though “Legacy 1.x bindings” is enabled. Then I go to Services → MQTT system broker connection → Manage and tried to configure it like I had used it under MQTT 1.

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

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

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#<broker>.clientId=<clientId>

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.
#MQTTBroker.user=openhabvm

# Optional. Password to authenticate with the broker.
#MQTTBroker.pwd=<haha, currently not, but better you should not know>

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
MQTTBroker.qos=0

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#<broker>.retain=<retain>

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
MQTTBroker.async=false

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

I was also using an MQTT Eventbus:

# Name of the broker as it is defined in the openhab.cfg. If this property is not available, no event bus MQTT binding will be created.
broker=MQTTBroker

# When available, all status updates which occur on the openHAB event bus are published to the provided topic. The message content will
# be the status. The variable ${item} will be replaced during publishing with the item name for which the state was received.
statePublishTopic=/messages/states/${item}

# When available, all commands which occur on the openHAB event bus are published to the provided topic. The message content will be the
# command. The variable ${item} will be replaced during publishing with the item name for which the command was received.
#commandPublishTopic=

# When available, all status updates received on this topic will be posted to the openHAB event bus. The message content is assumed to be
# a string representation of the status. The topic should include the variable ${item} to indicate which part of the topic contains the
# item name which can be used for posting the received value to the event bus.
#stateSubscribeTopic=

# When available, all commands received on this topic will be posted to the openHAB event bus. The message content is assumed to be a
# string representation of the command. The topic should include the variable ${item} to indicate which part of the topic contains the
# item name which can be used for posting the received value to the event bus.
commandSubscribeTopic=/messages/commands/${item}

So maybe later I have to do this tutorial: MQTT 2.5 Event Bus

One of my clients are using this configuration for MQTT:

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

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

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

# Optional. User id to authenticate with the broker.
#MQTTBroker.user=openhabvm

# Optional. Password to authenticate with the broker.
#MQTTBroker.pwd=<nope, not again, but nice try my friend>

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#MQTTBroker.retain=false

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
MQTTBroker.async=false

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

And the mqtt-eventbus.cfg:

# Name of the broker as it is defined in the openhab.cfg. If this property is not available, no event bus MQTT binding will be created.
broker=MQTTBroker

# When available, all status updates which occur on the openHAB event bus are published to the provided topic. The message content will
# be the status. The variable ${item} will be replaced during publishing with the item name for which the state was received.
#statePublishTopic=

# When available, all commands which occur on the openHAB event bus are published to the provided topic. The message content will be the
# command. The variable ${item} will be replaced during publishing with the item name for which the command was received.
commandPublishTopic=/messages/commands/${item}

# When available, all status updates received on this topic will be posted to the openHAB event bus. The message content is assumed to be
# a string representation of the status. The topic should include the variable ${item} to indicate which part of the topic contains the
# item name which can be used for posting the received value to the event bus.
stateSubscribeTopic=/messages/states/${item}

# When available, all commands received on this topic will be posted to the openHAB event bus. The message content is assumed to be a
# string representation of the command. The topic should include the variable ${item} to indicate which part of the topic contains the
# item name which can be used for posting the received value to the event bus.
#commandSubscribeTopic=

The MQTT items were online, but I could not access them via MQTT.fx. So I mean that I couldn’t connect to the broker, not that I couldn’t subscribe to Topics.

With netstat I can see that Mosquitto is really running under 1883 and of course the port is not blocked. Also 0.0.0.0. This leads me to believe that the actual MQTT/mosquitto configuration is already not working.

I tried it with the “public” IP-Address 192.168.0.5, localhost and of course 127.0.0.1.

Inside MQTT.fx I have configured following:

Profile Name: OpenHAB-MQTTBroker (Mosquitto)
Profile Type: MQTT Broker
Broker Address: 192.168.0.5
Broker Port: 1883
Client ID: <generic>

General
Connection Timeout: 30
Keep Alive Interval: 60
Clean Session: Yes
Auto Reconnect: No
MQTT-Version: Use default

User Credentials
of course empty

SSL/TLS
Enable SSL/TLS: no
Protocol: TLSv1.2

Proxy
Use http proxy: no

LWT
also empty

It would be nice if you could explain to me what I have to configure step by step and how. If I go via the Inbox and MQTT Thing Binding, the Thing was also displayed as online, but no connection to the broker via MQTT.fx could be established.

Thanks in advance!

It’s hard to ignore it because if you don’t fix that problem it can cause the problem you are describing. In other words, if you don’t fix the REST Docs has moved error it can prevent other add-ons from being installed too.

That is to configure an embedded MQTT broker built into OH (called Moquette) which would replace Mosquitto. It is not how you configure openHAB to connect to an MQTT broker. Moquette was abandoned by the upstream project so it’s been removed in OH 3 and not recommended for use in OH 2.5. Remove those settings and the System MQTT broker if you installed that as a separate addon. I don’t remember how all that works but ultimately your problem is likely that you are trying to run two MQTT brokers on the same host on the same ports at the same time.

Instead what you need to do is create an MQTT Broker Thing and populate it with the configuration to connect to your Mosquitto broker.

After some delay, the MQTT 1 binding is now visible and installable again.

The problem I had with Mosquitto was actually due to the new installation. It wanted to use IPv6 instead of IPv4. Consequently, I added socket_domain ipv4.

For now, it means my system is up and running again. I can then test MQTT 2 in parallel.