Login to mosquitto-broker fails after last update

Typo - password not passwork.

settings → devices & services → Mosquitto broker. configure → Re-configure MQTT → re-enter password here → Next → Submit

1 Like

Thanks but the part that I don’t get is ‘the mosquitto user I created for HA’. Do we have to create a user in HA that has the same username and password as the mosquito broker name and password?

I had the same issue. I was trying to get the data that is being published by program in raspberry pi using Paho-MQTT. I added this line client.username_pw_set(‘username’,‘password’) above the client.connect(broker) and it worked. The username and password should match with Home assistant user in the MQTT settings. More info can be found in the link below.

https://techoverflow.net/2021/12/27/how-to-set-username-password-in-paho-mqtt/

hope it help.

In the mosquito addon config I have defined users for all mqtt clients. One of this users is for home assistant, so that’s the username and password I used.

You should not define any users in the addon configuration. Set up HA users with passwords. Do it here Open your Home Assistant instance and show your users.

It even says so in the GUI for the addon:

A list of local users that will be created with username and password. You don’t need to do this because you can use Home Assistant users too, without any configuration.

2 Likes

So, do i?

  1. provide no user and password in the mosquitto add-on configuration
  2. create a HA user and password that will be used to connect to the mosquitto broker
  3. use the user and password from step 2 in other addons such as zigbee2mqtt, RTL_433 to MQTT Bridge, etc
    Thanks for the help.
    Also, fwiw my current setup worked fine for years until a recent update and I’m not quite sure what changed.
1 Like

You’re surely right, but my env has been configured like this for (literally) years since the inception of hassio, and long before the mosquitto addon was clever enough to integrate with HA in this way. Good to know there is a best practice and thanks for keeping me updated. I might migrate to use it sometime, but for now “if it aint broke…”.

Yes that’s correct.

Thanks for the reply.
I have removed the user and password from the Mosquitto broker config and instead created a HA user with the same values. Everything still works fine as before but I am still getting many, many of these errors in the Mosquitto broker logs.

error: received null username, clientid or topic, or access is equal or less than 0 for acl check

I don’t know what is causing this. My mqtt addons all use the correct user and password and they are working fine.
I think that these errors started with the last supervisor update but I’m not 100% sure.
thanks again.

I tried the mqtt-explorer to login to my HA-Mosquitto-Broker and it worked.
In the logfile of the broker the username appeared.

But when I try to send from my php-mqtt client there’s no username in the broker-log.

I think it’s maybe a problem with php-mqtt but I can’t reach the developer.

Is anybody able to check this?

here is my php-mqtt code:

<?php

require __DIR__ . '/vendor/autoload.php';
use \PhpMqtt\Client\MqttClient;
use \PhpMqtt\Client\ConnectionSettings;

$mqtt_server   = 'raspberrypi';
$mqtt_port     = 1883;
$clientId = 'heatronic';
$mqtt_username = 'php-mqtt';
$mqtt_password = '***********';
$clean_session = false;

$mqtt = new MqttClient($mqtt_server, $mqtt_port, $clientId);

$connectionSettings  = new ConnectionSettings();
$connectionSettings
  ->setUsername($mqtt_username)
  ->setPassword($mqtt_password)
  ->setKeepAliveInterval(60)
  ->setLastWillTopic('home/heizung/last-will')
  ->setLastWillMessage('client disconnect')
  ->setLastWillQualityOfService(1);

$mqtt->connect($connectionSettings, $clean_session);

$mqtt->publish('home', 'TEST', 0, true);
  
$mqtt->disconnect(); 

?>

The code works.
I receive the value in HA, but unfortunately as unknown user

1 Like

If you received the message in HA, is there a further problem?

Yes, I’m still on broker-version v6.0.2
When I update to 6.1.x I don’t receive any value because of the login problem

sorry understood.

Check the acl file has the homeassistant an addons user defined as per the docs for the addon.

what is an acl file?

Just in case it helps someone, I found out how to stop the error msgs in the mosquitto logs.
Changing the location where the user and password was being entered from the mosquitto config to HA users did not help. What finally worked was changing the mosquitto config parameter active: false to active: true. And then changing the \share\mosquitto\accesscontrollist.txt file as follows:

user addons
topic readwrite #

user homeassistant
topic readwrite #

user XXXXXXX  (replace XXXXXXX with a user that is defined in HA directly)
topic readwrite #

Then restart the mosquitto addon.

Nice hint but doesn’t work for:

rror: received null username or password for unpwd check
1655652494: Client <unknown> disconnected, not authorised.

Any solution would be really appreciated…

1 Like

no installation under that path :confused:

Can somebody tell me where I can find the installation of the mosquitto-broker-addon and where (the heck) do I find the debug.log when debugging is enabled?

I get exactly the same error message since upgrading from 6.0.1. The client that isn’t working anymore is my Roborock with valetudo software. In its configuration it shows the URL:

mqtt://192.168.178.3/valetudo:pwd

The broker shows the message “error: received null username or password for unpwd check”. If it was working before, could it be that the URL syntax isn’t correct, but that user and password were skipped in the earlier version?