[SOLVED] Mqtt client setup on openhabian

  • Platform information: openhabian latest, raspberry pi

I have mosquito broker running on another pi.
I can publish and subscribe to it from other PC’s and device on my net.

After running openhabian-config and adding mosquitto, in a terminal window I issue:

mosquitto_sub -h 192.168.53.105 -d -u mquser -P secret -t /dev/test

it responds:

Client mosqsub/1448-openHABian sending CONNECT
Client mosqsub/1448-openHABian received CONNACK
Client mosqsub/1448-openHABian sending SUBSCRIBE (Mid: 1, Topic: /dev/test, QoS: 0)
Client mosqsub/1448-openHABian received SUBACK
Subscribed (mid: 1): 0

It never sees publishes from other devices, while other subscribers do.

I assume I need this to work before openhab can work with the mqtt binding?

What am I missing?

Edit: subsequently I tried:
mosquitto_sub -t ‘#’ -v -h 192.168.53.105 -u mquser -P secret

AND it sees the publish from other devices…but, the subscribe shown above does not.

If you have the mosquitto broker running in another pi, you don’t need to install mosquitto on the openhabian pi too.

Install the mqtt binding in the paperUI
This will create a file called mqtt.cfg located in the config/services folder
Edit this file to include the details of your already running broker and OH will connect to that broker

See:
https://www.openhab.org/addons/bindings/mqtt1/

and:

By the way, I use this set-up too, I have a mosquitto broker running alone on a pi-zero. That’s all it is running. And OH is running on a recycled HP thin client.

Right, that’s why I started trying to figure out why I get nothing in OH…I followed that tutorial:

cat /srv/openhab2-conf/services/mqtt.cfg results in:

#
# 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
redpi_mqtt_broker.url=tcp://192.168.53.105: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.
redpi_mqtt_broker.user=mquser

# Optional. Password to authenticate with the broker.
redpi_mqtt_broker.pwd=secret

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

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

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

cat /etc/openhab2/items/sensors.items results in:
Number mqtt_pressure “Tank Pressure [%.1f]” {mqtt="<[redpi_mqtt_broker:dev/test:state:default]"}

In paperui I see an Item call Tank Pressure, in Add-ons the the MQTT binding shows as installed (but does not show up in Bindings), in HABpanel I added a button and it only updates the value when the Run button of the edit dashboard is clicked. BUt doesn’t update after that.

It shouldn’t be a button. Add a dummy item.
If it updates it means everything is working. I don’t think the button widget is meant for that purpose.

Hmm…I added a dummy widget and it updates!

I deleted the button and then added a new button…and it works now!

Thanks! :smiley:

Cool please mark the solution.