Hi, I’ve been struggling to fix this for some weeks now. I’m running homeassistant 0.90.2 in a venv on hassbian. Everything was working fine for a few years - then mqtt became a bit unreliable and on investigation I believed I’d run out of disk space and deleted the largest log files I found. I think it is possible that in so doing I’ve created a permissions problem but I cannot for the life of me overcome it.
Below is my attempt to succinctly summarise current issue and actions:
SYMPTOM: attempting to publish to broker (Mosquitto defined in configuration.yaml by including host IP, username, pword, port) results in error connection refused:
login as: pi
[email protected]’s password:
Linux hassbian 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Jul 12 15:47:48 2019 from 192.168.1.150
pi@hassbian:~ $ mosquitto_pub -d -u *** -P *** -t “mg/zone1” -m “123”
Error: Connection refused
To rule out authentication issue - recreate username and password in a new password file:
pi@hassbian:~ $ mosquitto_passwd -c newpwordfile ***
(password then set for the username above)
mosquitto.conf then edited as follows (conf file is v lengthy so only showing
what I think is relevant here - tell me if you need to see other areas)
log_dest file /var/log/mosquitto.log
allow_anonymous false
(I have run with allow_anonymous true but still get connection refused)
listener 9001
protocol websockets *
listener 1883
user ***
password_file /etc/mosquitto/newpwordfile
after reboot the following symptoms remain. mosquitto seems to have loaded and exited (why?) cleanly.
pi@hassbian:~ $ sudo service mosquitto status
● mosquitto.service - Mosquitto MQTT Broker daemon
Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sun 2019-07-14 14:12:16 UTC; 1min 10s ago
Process: 365 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d (code=exited
Main PID: 365 (code=exited, status=0/SUCCESS)
Jul 14 14:12:16 hassbian systemd[1]: Started Mosquitto MQTT Broker daemon.
pi@hassbian:~ $ mosquitto_pub -d -u *** -P *** -t “mg/zone1” -m “50”
Error: Connection refused
To try to help you see what is going on, here are the contents of mosquitto.log (much of this was previous, will rerun after deleting to get fresh data). The only way I can get broker to accept connections is to run mosquitto -d and it will be in that scenario that much of the below log traffic would have been generated.
1561238678: mosquitto version 1.6.2 starting
1561238678: Config loaded from /etc/mosquitto/mosquitto.conf.
1561238678: Opening ipv4 listen socket on port 1883.
1561238678: Opening ipv6 listen socket on port 1883.
1561238678: New connection from 192.168.1.166 on port 1883.
1561238678: New client connected from 192.168.1.166 as zone1 (p2, c1, k15, u’’).
1561238679: New connection from 192.168.1.144 on port 1883.
1561238679: New client connected from 192.168.1.144 as ESPClient_84:F3:EB:B3:95:23 (p2, c1, $
1561238679: New connection from 192.168.1.167 on port 1883.
1561238679: New client connected from 192.168.1.167 as zone2 (p2, c1, k15, u’’).
1561238689: New connection from 192.168.1.166 on port 1883.
1561238689: Client zone1 already connected, closing old connection.
1561238689: New client connected from 192.168.1.166 as zone1 (p2, c1, k15, u’’).
1561238692: New connection from 192.168.1.167 on port 1883.
1561238695: Client zone2 already connected, closing old connection.
1561238695: New client connected from 192.168.1.167 as zone2 (p2, c1, k15, u’’).
1561238698: Socket error on client zone1, disconnecting. *
1561238698: New connection from 192.168.1.166 on port 1883.
1561238698: New client connected from 192.168.1.166 as zone1 (p2, c1, k15, u’’).
1561238705: New connection from 192.168.1.167 on port 1883.
1561238705: Client zone2 already connected, closing old connection.
1561238705: New client connected from 192.168.1.167 as zone2 (p2, c1, k15, u’’).
1561238708: Socket error on client zone1, disconnecting.
1561238708: New connection from 192.168.1.166 on port 1883.
1561238708: New client connected from 192.168.1.166 as zone1 (p2, c1, k15, u’’).
1561238714: Socket error on client zone2, disconnecting.
1561238714: New connection from 192.168.1.167 on port 1883.
1561238714: New client connected from 192.168.1.167 as zone2 (p2, c1, k15, u’’).
1561238716: mosquitto version 1.6.2 terminating
1561238716: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
once log cleared (deleted) and mosquitto restarted (via reboot or via sudo service mosquitto start or via mosquitto -c /etc/mosquitto/mosquitto.conf) , symptoms same but nothing in log - it remains blank
pi@hassbian:~ $ sudo nano /var/log/mosquitto/mosquitto.log
pi@hassbian:~ $ mosquitto_pub -d -u *** -P *** -t “mg/zone1” -m “50”
Error: Connection refused
pi@hassbian:~ $ sudo nano /var/log/mosquitto/mosquitto.log (nothing there just blank)
pi@hassbian:~ $ sudo service mosquitto start
pi@hassbian:~ $ sudo nano /var/log/mosquitto/mosquitto.log (nothing there just blank)
pi@hassbian:~ $ mosquitto_pub -d -u *** -P *** -t “mg/zone1” -m “50”
Error: Connection refused
interestingly if I do the following to prove to myself it is using the conf file I want:
pi@hassbian:~ $ mosquitto -c /etc/mosquitto/mosquitto.conf
1563113985: Error: Unable to open log file /var/log/mosquitto.log for writing.
which makes me remember difficulties started when Pi appeared to run out of disk space and
I hurriedly deleted biggest log files… have I created permissions issues?
to check, first I had to recreate the log file with one space character inside because in ‘clearing’ the file I just deleted it and it seems mosquitto can’t create it when it initialises, then I chmod 777
pi@hassbian:/var/log/mosquitto $ ls -l
total 4
-rwxrwxrwx 1 root root 2 Jul 14 14:22 mosquitto.log
pi@hassbian:/var/log/mosquitto $ mosquitto -c /etc/mosquitto/mosquitto.conf
1563114267: Error: Unable to open log file /var/log/mosquitto.log for writing.
*looking at socket errors in old log contents above I have gone back into
mosquitto.conf and uncommented the websockets and listener 9001 lines and restarted
mosquitto but symptom same as last command shown - error opening log file for writing.
Not sure what to do next…?