Mosquitto errors


the mqtt.cfg fil

# 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

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

# Optional. User id to authenticate with the broker.

# Optional. Password to authenticate with the broker.

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

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

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to 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/

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

hobe this helps

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):


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


i have try to edit my post hope you can help me :slight_smile:

1 Like


For the mqtt.cfg file:
Un-comment the following lines and replace <broker> with some name that you want to set (e.g. myMQTT)


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)

I have done this but is stil do not work what can i have done wrong
can i test if it is the mosquitto ther is not working or what can i do

i have an sonoff th16 i have flash the esp an it gives this log
13145766 : MQTT : Failed to connected to broker
13146268 : MQTT : Failed to connected to broker
13149802 : DHT : Temperature: 23.10
13149802 : DHT : Humidity: 43.80
13154806 : DHT : Temperature: 23.20
13154807 : DHT : Humidity: 43.80
13159812 : DHT : Temperature: 23.10
13159812 : DHT : Humidity: 43.80
13164817 : DHT : Temperature: 23.20
13164817 : DHT : Humidity: 43.70

and the setup her is

Protocol: Openhab
Locate Controller: user ip adresse
Controller IP:
Controller Port: 1883
Controller User: openhab
Controller Password: habopen
Sensor Delay: 5

You can test the Mosquitto MQTT Broker with the following commands:

Open a ssh login in one window and subscribe to all topics under openhab:

mosquitto_sub -u openhab -P habopen -t openhab/#

Open another ssh login in another window and publish a message (e.g. ON) to a topic (e.g. command) under openhab:

mosquitto_pub -u openhab -P habopen -t openhab/command -m ON

On the first window with the subscription, you should see the published message (ON)

Does this simple test work? (if yes: your MQTT Broker is working fine and you need to check the openHAB2 configuration of the MQTT Binding again)

Ps: You will need to have apt-get install mosquitto-clients for these pub & sub commands to work.

1 Like


i get this

Error: connection refused

If you get:

Connection Refused: not authorised.
Error: The connection was refused.

Then you password file needs to be fixed

Create a new one:

mosquitto_passwd -c /etc/mosquitto/passfile openhab

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

1 Like

i get this

switch to root first with:

sudo su

and then try again :slight_smile:
(or put sudo in front of every command since the user pi doesn’t have access to several system directories)

i stil get

and this is for systemctl status mosquitto

I am scratching my head … :slight_smile: It should have worked…

Try the following:

apt-get update
apt-get upgrade mosquitto

also: check the systemctl status mosquitto to see what it says…
Somehow your mosquitto server is not working…?

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

1 Like

i have now done apt-get remove mosquitto and then apt-get mosquitto and i get this status

and log

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:

pid_file /var/run/
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
allow_anonymous false
password_file /etc/mosquitto/passfile
1 Like

hi i removed mosquitto.conf and created a new one only

user mosquitto
port 1883

and get this :slight_smile:

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… :sunglasses:

now my conf file is

user mosquitto
port 1883
pid_file /var/run/
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
allow_anonymous false
password_file /etc/mosquitto/passfile

and i have run chown


disable persistence (set persistence false) and restart the broker. It should become active (running)
check the directory /var/lib/mosquitto/ for the permissions and if any file was created in there

… and start looking for a new SD Card :slight_smile: (it may have data corruption problems…)