OH2 don't even try to connect to mqtt

Ok i spent my second night readings lots of info on the subject without any success. I think i really need another person viewing the code to see something!

So my problem is that openhab doesn’t seem to communicate with mosquitto at all.

My setup is really simple:

Openhab2 and mosquitto installed on the same server (ubuntu)
My desktop to test (subscribe and publish)
An arduino board that only publish a string

They are all on the same network. From my desktop i see my arduino message. From my server i see both arduino and desktop message. But i never saw anything coming from my OH2 and OH2 don’t see any message. I’m able to see the arduino and desktop connecting on mosquitto log, but i don’t see my OH2 connecting.

In the karaf log i’ve put debug logging on org.openhab.io.transport.mqtt and org.openhab.binding.mqtt.

here’s the log (i clicked on my switch to get the last line there) :

openhab> log:tail | grep mqtt
22:41:19.056 [DEBUG] [penhab.io.transport.mqtt.MqttService] - Starting MQTT Service...
22:41:19.059 [DEBUG] [org.openhab.io.transport.mqtt       ] - ServiceEvent REGISTERED - {org.openhab.io.transport.mqtt.MqttService, org.osgi.service.cm.ManagedService}={service.pid=org.openhab.mqtt, component.name=MQTT Connection Service, component.id=200, service.id=319, service.bundleid=201, service.scope=bundle} - org.openhab.io.transport.mqtt
22:41:19.086 [DEBUG] [org.openhab.io.transport.mqtt       ] - BundleEvent STARTING - org.openhab.io.transport.mqtt
22:41:19.123 [DEBUG] [org.openhab.io.transport.mqtt       ] - BundleEvent STARTED - org.openhab.io.transport.mqtt
22:41:19.637 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:broker
22:41:19.638 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:topic
22:41:19.640 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:message
22:41:20.119 [DEBUG] [org.openhab.binding.mqtt            ] - BundleEvent STARTING - org.openhab.binding.mqtt
22:41:20.126 [DEBUG] [.binding.mqtt.internal.MqttActivator] - MQTT binding has been started.
22:41:20.158 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item 'arduinoTest' : 1 subscribers, 0 publishers
22:41:20.170 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item 'openhabtest' : 0 subscribers, 2 publishers
22:41:20.171 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item 'humidityTest' : 1 subscribers, 0 publishers
22:41:20.176 [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=213, service.id=340, service.bundleid=213, service.scope=bundle} - org.openhab.binding.mqtt
22:41:20.207 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - MQTT: Activating event bus binding.
22:41:20.209 [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=214, service.id=342, service.bundleid=213, service.scope=bundle} - org.openhab.binding.mqtt
22:41:20.227 [DEBUG] [org.openhab.binding.mqtt            ] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler}={event.topics=openhab/*, component.name=org.openhab.binding.mqtt.MqttItemBinding, component.id=215, service.id=343, service.bundleid=213, service.scope=bundle} - org.openhab.binding.mqtt
22:41:20.228 [DEBUG] [org.openhab.binding.mqtt            ] - BundleEvent STARTED - org.openhab.binding.mqtt
22:48:51.327 [DEBUG] [inding.mqtt.internal.MqttItemBinding] - Publishing command ON to test/openhab

I never saw the famous line : Starting MQTT broker connection …

I tired this without success :

delete file: /var/lib/openhab2/config/org/openhab/mqtt.config and let openHAB 2 reload your /etc/openhab2/services/mqtt.cfg

Here’s pretty much all my config related to it that i know of…

mqtt.cfg:

#
# 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
mosquitto.url=tcp://localhost:1883

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

# Optional. User id to authenticate with the broker.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

# 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.
mosquitto.retain=false

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

# 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>

addons.cfg (binding section):

# A comma-separated list of bindings to install (e.g. "sonos,knx,zwave")
binding = mqtt1,weather,nest,mios1,xbmc,zwave

# A comma-separated list of UIs to install (e.g. "basic,paper")
ui = paper,habmin,habpanel,basic,classic

# A comma-separated list of persistence services to install (e.g. "rrd4j,jpa")
persistence = rrd4j,mqtt,mapdb

# A comma-separated list of actions to install (e.g. "mail,pushover")
action = mios,mqtt,xbmc

karaf mqtt config:

openhab> config:edit org.openhab.mqtt
openhab> config:property-list
   mosquitto.async = true
   mosquitto.clientId = openhab
   mosquitto.retain = false
   mosquitto.url = tcp://localhost:1883
   service.pid = org.openhab.mqtt

karaf features:

openhab> feature:list | grep mqtt
esh-io-transport-mqtt                       | 0.9.0.b5         |          | Started     | distro-2.1.0                |
openhab-transport-mqtt                      | 2.1.0            | x        | Started     | distro-2.1.0                | MQTT Transport
openhab-action-mqtt                         | 1.10.0           | x        | Started     | addons-2.1.0                | MQTT Action
openhab-binding-mqtt1                       | 1.10.0           | x        | Started     | addons-2.1.0                | MQTT Binding
openhab-binding-mqttitude1                  | 1.10.0           |          | Uninstalled | addons-2.1.0                | OwnTracks (formerly MQTTitude) Binding
openhab-persistence-mqtt                    | 1.10.0           | x        | Started     | addons-2.1.0                | MQTT Persistence
openhab-action-mqtt                         | 1.10.0           | x        | Started     | openhab-addons-2.1.0        | MQTT Action
openhab-binding-mqtt1                       | 1.10.0           | x        | Started     | openhab-addons-2.1.0        | MQTT Binding
openhab-binding-mqttitude1                  | 1.10.0           |          | Uninstalled | openhab-addons-2.1.0        | OwnTracks (formerly MQTTitude) Binding
openhab-persistence-mqtt                    | 1.10.0           | x        | Started     | openhab-addons-2.1.0        | MQTT Persistence

items (all three are for testing for the moment):

String arduinoTest    "Arduino Test: [%s]"    (gArduino) {mqtt="<[mosquitto:arduino:state:default]"}
Switch openhabtest    "Openhab Test: [%s]"    (gArduino) {mqtt=">[mosquitto:test/openhab:command:ON:1],>[mosquitto:test/openhab:command:OFF:0]"}
Number humidityTest   "hum [%.d]"             (gArduino) {mqtt="<[mosquitto:hum:state:default]"}

I’m using my sitemap to toggle the switch.

uninstall mqtt action to see if things improve

2 Likes

Oh wow i didn’t see that one!

All i did is uninstall mqtt action from PaperUI and edit addons.cfg to remove mqtt from the action line. + reboot oipenhab.

Everything works like a charm now!

Thanks a lot! I’m pretty happy that it was that simple.

1 Like

I think that if you re-install the mqtt-action, it will be ok…

see:
i) https://github.com/openhab/openhab1-addons/issues/5038#issuecomment-313893889 &
ii) MQTT Stopped Working HELP!

Ps: addons.cfg :slight_smile:

hehe corrected!

I confirm, i just reinstall mqtt addon from paperui and added it back to addon.cfg + reload openhab and the mqtt still work.

thanks again!

oh god … i spent so long until i found this :wink:
hope i will make some progress now!

1 Like