# Mosquitto errors

**URL:** <https://community.openhab.org/t/mosquitto-errors/22685>\
**Category:** Bindings\
**Created:** [February 11, 2017, 5:04pm UTC](https://community.openhab.org/t/mosquitto-errors/22685 "2017-02-11T17:04:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 5:04pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/1 "2017-02-11T17:04:42Z")

</div>

Hi

i am new in openhab2 and MQTT mosquitto  
i used this [https://www.youtube.com/watch?v=AsDHEDbyLfg&index=3&list=PLbE4G0mzEl0pGnlhRxxELqYahZ4EWjVxn](https://www.youtube.com/watch?v=AsDHEDbyLfg&index=3&list=PLbE4G0mzEl0pGnlhRxxELqYahZ4EWjVxn) to setup my mosquitto but i keep geting error: Connection refused  
i am running my openhab2 and my mosquitto on my raspberry pi3  
can someboddy pls help me

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 5:38pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/2 "2017-02-11T17:38:59Z")

</div>

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?

The error (connection refused) is from which log?

---

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 5:51pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/3 "2017-02-11T17:51:43Z")

</div>

Hi

the mqtt.cfg fil

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

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

hobe this helps

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 7:01pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/4 "2017-02-11T19:01:36Z")

</div>

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

```auto

```

content\_goes\_here

```auto

```

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

---

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 7:25pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/5 "2017-02-11T19:25:36Z")

</div>

Hi

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

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 7:32pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/6 "2017-02-11T19:32:43Z")

</div>

Ok,

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

```auto
myMQTT.url=tcp://192.168.0.242:1883
myMQTT.clientId=openhab
myMQTT.user=openhab
myMQTT.pwd=habopen

```

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)

---

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 7:47pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/7 "2017-02-11T19:47:27Z")

</div>

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: 192.168.0.242  
Controller Port: 1883  
Controller User: openhab  
Controller Password: habopen  
Sensor Delay: 5

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 7:51pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/8 "2017-02-11T19:51:38Z")

</div>

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

```auto
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`:

```auto
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.

---

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 8:13pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/9 "2017-02-11T20:13:52Z")

</div>

hi

i get this

Error: connection refused

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 8:17pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/10 "2017-02-11T20:17:01Z")

</div>

If you get:

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

```

Then you password file needs to be fixed

Create a new one:

```auto
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](https://community.openhab.org/t/mosquitto-errors/22685/8)

Otherwise, check if the Mosquitto Broker is up and running: `systemctl status mosquitto`

---

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 8:35pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/11 "2017-02-11T20:35:43Z")

</div>

> [@Dim](#):
>
> chown mosquitto:mosquitto /etc/mosquitto/passfile

i get this

![](https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/c/cd2d0df39c21d1058fbb877eaa614077da76f148.png)

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 8:37pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/12 "2017-02-11T20:37:22Z")

</div>

switch to root first with:

```auto
sudo su

```

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

---

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 8:42pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/13 "2017-02-11T20:42:13Z")

</div>

> [@Dim](#):
>
> mosquitto\_pub -u openhab -P habopen -t openhab/command -m ON

i stil get  
 ![](https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/b/b07c1c4a38121c8a0fdaa863051af41de2f6132f.png)

and this is for systemctl status mosquitto  
 ![](https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/2/2c7f953a7901a4f7cf34f328f7c3d88bb25077c1.png)

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 8:46pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/14 "2017-02-11T20:46:50Z")

</div>

I am scratching my head … 🙂 It should have worked…

Try the following:

```auto
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…?

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 8:51pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/15 "2017-02-11T20:51:13Z")

</div>

> [@paulmann](#):
>
> and this is for 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`

---

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 8:57pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/16 "2017-02-11T20:57:29Z")

</div>

> [@Dim](#):
>
> systemctl status mosquitto

i have now done apt-get remove mosquitto and then apt-get mosquitto and i get this status  
¨  
 ![](https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/6/6f8c089509632fb3da18daec020ef0a161881df8.png)

---

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 8:59pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/17 "2017-02-11T20:59:56Z")

</div>

> [@Dim](#):
>
> /var/log/mosquitto/mosquitto.log

and log  
 ![](https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/7/7413b7b872c84d015d2f9fd31347c2dd265fafd1.png)

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 8:59pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/18 "2017-02-11T20:59:58Z")

</div>

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`

```auto
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:

```auto
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/passfile

```

---

<div class="post-metadata">

**Author:** ![paulmann](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/7bcc69/32.png) [@paulmann](https://community.openhab.org/u/paulmann)\
**Post date:** [February 11, 2017, 9:10pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/19 "2017-02-11T21:10:58Z")

</div>

> [@Dim](#):
>
> user mosquitto  
> port 1883

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

user mosquitto  
port 1883

and get this 🙂  
 ![](https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/c/c433bf8b000396757e17dff6133e305d9dee1116.png)

---

<div class="post-metadata">

**Author:** ![Dim](https://community.openhab.org/user_avatar/community.openhab.org/dim/32/4568_2.png) [@Dim](https://community.openhab.org/u/Dim)\
**Post date:** [February 11, 2017, 9:12pm UTC](https://community.openhab.org/t/mosquitto-errors/22685/20 "2017-02-11T21:12:46Z")

</div>

> [@paulmann](#):
>
> and get this 🙂

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… 🕶

[Next page](https://community.openhab.org/t/mosquitto-errors/22685.md?page=2)
