Post the following to check them: /etc/openhab2/services/mqtt.cfg file & /etc/mosquitto/mosquitto.conf file
Have you installed the MQTT Binding in PaperUI?
What do you want to do with OH2 and MQTT? Items, Persistence, other use case?
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace mybroker with an ID you choose.
#
# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
#<broker>.url=tcp://192.168.0.242:1883
# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
#<broker>.clientId=openhab
# Optional. User id to authenticate with the broker.
#<broker>.user=openhab
# Optional. Password to authenticate with the broker.
#<broker>.pwd=habopen
# 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=0
# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#<broker>.retain=false
# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#<broker>.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>
and the mosquitto.conf
# 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.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
allow_anonymous false
password_file /etc/mosquitto/pwfile2
listener 1883
i have install mqtt binding in papeUI and i like to use items
To make sure that I read the files correctly, do the following: Edit your post above (pencil icon, bottom right corner of post)
and include the contents of the config files in the following way (without the first space before the three tick marks):
content_goes_here
I don’t see a name for your broker in your mqtt.cfg
I see .url= and .clientId= but it should be something like: mybroker.url= etc
Your mosquitto.conf looks good. Note: since you have disabled anonymous logins (that’s good), make sure that you have created the user openhab with password habopen on the Mosquitto Broker (using the password file /etc/mosquitto/pwfile2). Have you done this step? (with the mosquitto_passwd command)
Enter habopen for the password (twice)
Change in mosquitto.conf the password_file /etc/mosquitto/passfile
Change ownership of the new file: chown mosquitto:mosquitto /etc/mosquitto/passfile
Restart the Broker (systemctl restart mosquitto)
Try again the pub & sub test commands
Otherwise, check if the Mosquitto Broker is up and running: systemctl status mosquitto
it’s broken… It shows “active (exited)” when it should be showing “active (running)”…
Check the /var/log/mosquitto/mosquitto.log for errors
try to apt-get update and then apt-get upgrade mosquitto
If this doesn’t help: apt-get remove mosquitto and then apt-get install mosquitto
Check the permissions of the /var/lib/mosquitto/ directory.
It should be owned by the user mosquitto.
To fix this: chown -R mosquitto:mosquitto /var/lib/mosquitto
Check if the file mosquitto.db has been created in there.
Otherwise…It may be a problem with your mosquitto.conf file… (some syntax error or something similar)
back it up and remove it from /etc/mosquitto/ folder put in the following simple options in a new one and try to systemctl restart mosquitto
user mosquitto
port 1883
The Broker should become active (running)
If this works, start adding back the other options in your new mosquitto.conf, like:
It’s up and running (but without authentication)
So… the problem must be the persistence_location (/var/lib/mosquitto/)
Change the ownership of that directory: chown -R mosquitto:mosquitto /var/lib/mosquitto
and put back the options in your mosquitto.conf and restart the broker
It should work…