Connect to local mqtt

I installed mqtt on local as below:

docker run -itd -p 1883:1883 -p 9001:9001 -v /home/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf -v mosquitto_data:/mosquitto/data -v mosquitto_log:/mosquitto/log --name mosquitto eclipse-mosquitto

It seems work fine, as I verified with mqtt.fx. I can connect, and can subscribe and publish.

However in my HA in another container I can’t connect.

mqtt:
  broker: 127.0.0.1
  port: 1883
  discovery: true
  discovery_prefix: homeassistant
  birth_message:
    topic: "hass/status"
    payload: "online"
    qos: 1
    retain: true

Here is the error I saw from HA log:

2019-11-22 15:42:51 ERROR (MainThread) [homeassistant.components.mqtt] Failed to connect due to exception: [Errno 111] Connection refused

Question:

  1. what could be issue for the connection refused?
  2. is there UI for mqtt to setup user/password?

Thanks.

That’s not going to work. Your mqtt container has a different ip address since its a container.
And if you’re running ha also in a container, 127.0.0.1 would be the internal ip address of the container. You’ll need the ip address of your server and make sure ports are correctly open (seems to be the case from your docker command)

Thanks! yes I had to use the ip address of the server. It works.

I also figured out how to setup user/password following this guide: https://medium.com/@eranda/setting-up-authentication-on-mosquitto-mqtt-broker-de5df2e29afc

1 Like