Today I installed the Mosquitto broker on Hass.io. Only starts working after disable port 1883 in the Hass.io set-up. In Portainer I see that the container is running and using port 1884:1884 plus some other ports (not 1883).
After that tried to set-up MQTT integration in HA using configuration/Integrations (not configuration.yaml), but not able to connect to the broker on servers IP address (hass.io server) and port 1884. Port 1883 it connects to without delay, but that is not what I configured.
With the container up and running, using top command on the Linux server I see Mosquitto active. schutting down the container and its not visible in top anymore.
Am I missing a step in the configuration of Mosquitto here, or is there another problem?
Talking to my self here
After removing the manually configured MQTT integration and rebooting the (NUC) server, HA offered a detected MQTT instance. This does not require configuration, just one mouse click.
In the MQTT log of Hass.io a connection shows:
1577118238: New client connected from 172.30.32.1 as auto-E7F8C019-9E16-C5EE-E017-xxxxxxxxx (p2, c1, k60, u’homeassistant’)
Now the main question: this is not according to the installation description in HAss.io. But is this correct or not?
And secondly: does the serving application that sends the messages to Mosquitto require a username/password or not?
That’s what I’ve done: click ‘configure’. But i’m only presented one option here, and that is ‘Enable discovery’, no other fields to fill. Those are only available if you click the + and select MQTT from the list of integrations. And with those fields filled I can’t configure port 1884 (no connection possible) 1883 is connecting, but that is not configured in Mosquitto.
The port 1883 is configured in the BROKER… not the integration. Port 1884 can also be used for MQTT SSL connections…
Install the broker and set active: false in the broker; Don’t configure a user… either create or use a regular home Assistant user for MQTT in your devices. You DON’T need to setup a user in the broker.
If you can’t make it work, post your broker config.
If you use MQTT discovery, you need to make sure you have enabled discovery in your devices but you haven’t said what devices you are using.
You must have another MQTT addon or broker using 1883. Are you sure you didn’t install the MQTT community addon as well as the Core MQTT addon? How did you install hassio?
1577111527: Opening ipv4 listen socket on port 1883.
1577111527: Opening ipv6 listen socket on port 1883.
1577111527: Opening websockets listen socket on port 1884.
I also see in the same log:
1577118238: New connection from 172.30.32.1 on port 1883. [INFO] found homeassistant on local database
1577118238: New client connected from 172.30.32.1 as auto-E7F8C019-9E16-C5EE-E017-xxxxxxxxx (p2, c1, k60, u’homeassistant’).
1577118730: Saving in-memory database to /data/mosquitto.db.
1577120531: Saving in-memory database to /data/mosquitto.db.
Am I correct to conclude that the link to Homeassistant should be working?
Unfortunately things go bad: Homeassistant disconnects immediately.
1577203214: New connection from 172.30.32.1 on port 1883.
1577203214: New client connected from 172.30.32.1 as auto-31CAF3B4-DCAE-0BFA-E66E-5A3D0F8D89F3 (p2, c1, k60, u’homeassistant’).
1577203214: Client auto-31CAF3B4-DCAE-0BFA-E66E-5A3D0F8D89F3 disconnected.
So I see several issues:
1: it is not clear which port number is used by Mosquitto: 1883 seems standard but can’t be configured. Maybe solved in the newer version of Mosquitto.
Port 1884 is shown in the container set-up, but not seen using Linux command netstat -tulpn. Is firewall configuration required here?
2: the way of configuring HA can be done in 2 ways (using the discovered MQT that has no fields to fill or the manual one using the + and does include fields to fill. It’s not clear which of the 2 methods is correct
3: documentation of HA needs updating. This should point to the correct configuration method with a warning not to use the other one, and a description on how to configure the account the publishing system (in my case the smart meter appliance) has to use
4: there is a newer version of Mosquitto, so an update of the Hass.io addon is welcome, to rule out bugs in the current version
Still having problems with the HassIO 5.1 version of Mosquitto, let me update to show where i’m stuck
1: In HassIO developers tools MQTT tab I enable listen to all topics using #
2: Using the publishing tool on the same page I can send a message that is shown in the listening part
So this look promising, but using the Mosquitto provided way of sending a test message is not received in HassIO. This is what I sent from the command line on the HassIO server (not in the Mosquitto container) and what is shown as debug response:
That port 1883 could not be configured in Mosquitto config was still bothering me. Together with the fact that messages where received somewhere as shown by MQTT-explorer (great tool!), got me reviewing the steps already followed.
As written earlier, while suspecting Mosquitto was already installed I used the apt command to purge Mosquitto. That resulted in a message that Mosquitto was not installed.
After uninstalling the HassIO Mosquitto and restarting HA, messages where still processed, so there was an instance of a mqtt application processing the messages…
After finding the PID and using a command to see what application belonged to it, I saw that it was a snap installed application.
Using ‘snap list —all’ (2 dashes) I saw that Mosquitto was installed.
Using the command ‘snap remove mosquitto’ removed all appearances and from there on I could reinstall the HassIO version and initiate the integration. Mqtt is now working flawlessly
Conclusion I now have is that in Ubuntu 19.10 Mosquitto is installed by default, because I did not do that manually.
Running Ubuntu 19.10 on my desktop and this is not true, but during the OS installation process you are given options to install snaps. If you told it that it was going to act as an MQTT broker (one of the options) then it installed Mosquitto. It is not, however, installed by default.