New MQTT Error

Everything was working fine until this yesterday. Then I noticed I couldn’t control my Sonoff lights (MQTT).

I rebooted the Pi and now I get an invalid config for MQTT notification. Checking the log I get the following:

2017-11-12 10:43:55 ERROR (MainThread) [homeassistant.setup] Error during setup of component mqtt
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py”, line 191, in _async_setup_component
result = yield from component.async_setup(hass, processed_config)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/init.py”, line 387, in async_setup
success = yield from hass.data[DATA_MQTT].async_connect()
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/init.py”, line 497, in async_connect
self._mqttc.connect, self.broker, self.port, self.keepalive)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/paho/mqtt/client.py”, line 760, in connect
return self.reconnect()
File “/srv/homeassistant/lib/python3.4/site-packages/paho/mqtt/client.py”, line 887, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File “/usr/lib/python3.4/socket.py”, line 509, in create_connection
raise err
File “/usr/lib/python3.4/socket.py”, line 500, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Stranger still is that I haven’t changed anything at all. I haven’t even logged in to the pi with putty or WinSCP in over a month. It was all working ans suddenly MQTT is broken.

Any idea what to check based on the error above?

This is normally an invalid username or password. Can you connect to your broker with some other client using the username and password in your configuration.yaml?

@gpbenton

I just tried MQTT Snooper on my phone and can’t connect with that either.

I have rebooted my router, verified that I have the port 1883 forwarded on my router to the pi IP address.

I reset my MQTT password to what it is in my configuration file (just in case it had gotten changed/corrupted - no reason to believe that it was tho).

$ sudo mosquitto_passwd /etc/mosquitto/pwfile -username-

I then tried to completely recreate the same username with the same password that I currently supposed to have in there.

$ sudo mosquitto_passwd -c /etc/mosquitto/pwfile -username-

I verified that MQTT and MQTT_client was installed on the pi and they both say they are the latest version.

$ sudo apt-get install mosquitto
$ sudo apt-get install mosquitto-clients

Still the same error.

From this I assume that you are accessing mosquitto through an external connection. If this is encrypted is it possible that your certificate has expired? That would explain the failure without you touching anything.

I can’t be much help with that as my installation is entirely local.

My home assistant is local to my MQTT broker. It’s installed on the same Pi.

My pertinent part of configuration.yaml:

mqtt:
  broker: 192.168.1.125
  port: 1883
  client_id: home-assistant-1
  username: !secret MQTT_user  
  password: !secret MQTT_password

I was just trying to eliminate the most possibilities.

I burned an older version from a backup and I am able to subscribe to the topic on my PC with MQTTFx so it has to be related to my HA setup.

I will reburn the problem version to the SD card and see if the certificate on there has expired. I don’t think it’s related but that makes the most sense right now. Thanks!

just put the latest version SD card back in.

SSL Cert doesn’t expire for another 40 days.

Still having the MQTT issue.

Would it be best to just uninstall MQTT and reinstall?

How would I do that?

Are there any interesting lines in the log file (usually /var/log/mosquitto/mosquitto.log)?

I think I would try configuring mosquitto to work without a username and password, to see if it is some corruption there.

But then removing and reinstalling would probably be best anyway. If you installed using apt-get, make sure you do

sudo apt-get purge mosquitto

as this gets rid of all the configuration files. remove removes the binaries and service but leaves the configuration files, which will leave you with the same problem.

1 Like

the mosquitto log file is completely empty. But I’m not sure how reliable that file location is since the date on it is december 1969. I did search and didn’t find any other log files.

I think i’m going to uninstall & reinstall and see if that works.

Purging and reinstalling did the trick.

Thanks very much for your help.

Still would be nice to know the root cause…