Login to mosquitto-broker fails after last update

The addon has logs. Also, can you test with mosquitto_sub (or _pub) and post the output?

This time I was able to fix it with a simple restart of the addon. I posted this above, but the logs are just LOADED with this:

2022-09-22 08:52:07: New connection from 192.168.1.182:64294 on port 1883.
error: received null username or password for unpwd check
2022-09-22 08:52:07: Client <unknown> disconnected, not authorised.
2022-09-22 08:52:12: New connection from 172.30.32.1:58072 on port 1883.
error: received null username or password for unpwd check
2022-09-22 08:52:12: Client <unknown> disconnected, not authorised.
2022-09-22 08:52:17: New connection from 172.30.32.1:45538 on port 1883.
error: received null username or password for unpwd check

The 192 address is my laptop. It’s only connection to MQTT is via HASS.Agent, which is obviously using a password. The 172 seems like it must be a local docker container connecting. I’m wondering if that’s HA itself.

Lest it should help, my mosquitto broker also failed after the last update.

The log fills with these every few seconds:

error: received null username or password for unpwd check
2022-09-27 16:34:09: Client <unknown> disconnected, not authorised.
2022-09-27 16:34:10: New connection from 172.30.32.1:49388 on port 1883.
error: received null username or password for unpwd check

I’d noted that the broker failed to connect, so had restarted the MQTT add-on. My broker options are:

broker: core-mosquitto
port: 1883
username: mqtt-user
password: [redacted]

These settings were working previously. This is on HA Blue, if that helps. I see there’s an update to 2022.9.7, so perhaps that’ll fix it.

OK. I updated to 2022.9.7 and restarted. Whilst my devices are still broken, I can see that the MQTT broker seems to be working.

To test:

  • I went to Settings → Integrations and found the Mosquitto broker MQTT.
  • I used the configure screen to listen to a topic (homeassistant/status).
  • I used the publish a packet option to send a payload on this topic (payload: online).

I do see they payload come through, so it looks like the issue isn’t in the broker or MQTT addon. The broker lists my (14) devices and (66) entities, but all show a ‘Restored’ warning circle for their status.

The next part of the diagnosis is probably the Ring-MQTT with Video Streaming add-on.

That’s using the following url, and I’m thinking maybe this is the one causing the log entries…
mqtt://auto_username:auto_password@auto_hostname

Edit: Given it a few minutes to write this reply. My devices are back online. OK. Unsure what made it start working again.

I found this thread when hass agent started getting this error for me

So if I’m reading this correctly, you were able to use the pethublocal HA addon?

Did we ever entirely figure out what is going on here?

I have several ESP8622 devices successfully publishing data to my MQTT instance running in HA using authentication. I am attempting to publish data using php-mqtt and receiving the same error messages in the MQTT Broker log about receiving null for the username or password:

2023-02-26 08:47:15: New connection from 192.168.1.130:56734 on port 1883.
error: received null username or password for unpwd check
2023-02-26 08:47:15: Client <unknown> disconnected, not authorised.

I have identical credentials specified for the php-mqtt script as used for the ESP8622 devices, it’s not a credentials problem (but maybe php-mqtt isn’t sending them properly?) The bare-bones script I am trying to debug with is as follows, you can see I specify the MQTT version, I’ve tried 3.1 and 3.1.1

<?php

require('../vendor/autoload.php');

use \PhpMqtt\Client\MqttClient;
use \PhpMqtt\Client\ConnectionSettings;

$server   = 'ADDRESS_IS_HERE';
$port     = 1883;
$clientId = 'CLIENT_ID_IS_HERE';
$username = 'USERNAME_IS_HERE';
$password = 'PASSWORD_IS_HERE';
$clean_session = false;
$mqtt_version = MqttClient::MQTT_3_1_1;

$connectionSettings  = new ConnectionSettings();
$connectionSettings
  ->setUsername($username)
  ->setPassword($password);

$mqtt = new MqttClient($server, $port, $clientId, $mqtt_version);
$mqtt->connect($connectionSettings, $clean_session);
printf("client connected\n");

for ($i = 0; $i< 10; $i++) {
  $payload = array(
    'protocol' => 'tcp',
    'date' => date('Y-m-d H:i:s'),
    'url' => 'https://github.com/emqx/MQTT-Client-Examples'
  );
  $mqtt->publish(
    // topic
    'emqx/test',
    // payload
    json_encode($payload),
    // qos
    0,
    // retain
    true
  );
  printf("msg $i send\n");
  sleep(1);
}

?>

Looking at the apache error logs where the php script lives it tells the same story:

Uncaught PhpMqtt\\Client\\Exceptions\\ConnectingToBrokerFailedException: [6] Establishing a connection to the MQTT broker failed: The configured broker responded with unauthorized. in redacted/vendor/php-mqtt/client/src/MessageProcessors/Mqtt31MessageProcessor.php:252
Stack trace:
#0 redacted/vendor/php-mqtt/client/src/MqttClient.php(380): PhpMqtt\\Client\\MessageProcessors\\Mqtt31MessageProcessor->handleConnectAcknowledgement()
#1 redacted/vendor/php-mqtt/client/src/MqttClient.php(159): PhpMqtt\\Client\\MqttClient->performConnectionHandshake()
#2 redacted/vendor/php-mqtt/client/src/MqttClient.php(144): PhpMqtt\\Client\\MqttClient->connectInternal()
#3 redacted.php(23): PhpMqtt\\Client\\MqttClient->connect()
#4 {main}\n  thrown in redacted/vendor/php-mqtt/client/src/MessageProcessors/Mqtt31MessageProcessor.php on line 252

Mosquitto broker
Current version: 6.1.3

Home Assistant 2023.2.5
Supervisor 2023.01.1
Operating System 9.5
Frontend 20230202.0 - latest

Well as follow-up… I’ve managed to figure this out myself. Hopefully the following helps someone else.

The tutorials I was following set up the Connectionsettings as such:

$connectionSettings  = new ConnectionSettings();
$connectionSettings
  ->setUsername($username)
  ->setPassword($password);

however this wasn’t working. In looking at official examples I noticed they were being setup like so:

  $connectionSettings = (new ConnectionSettings)
  ->setUsername($username)
  ->setPassword($password);

which works perfectly…

1 Like

hi, i have the same problem and i can’t solve it, i didn’t understand how i can connect to mqtt and give these commands. could you help me please? Thank you very much

Exactly what errors are you having, and what idea your setup?

i tried different guides but i always get this error, now i followed this guide https://www.youtube.com/watch?v=MHg4R7C6Mxg&ab_channel=SmartLivingItalia

i tried with this guide too but i still get the same error in the log

Ok so can I take it that you have

Home assistant operating system?
The mosquitto addon?

What is the setup in the addon? Via yaml please.

PS home assistant is not documented on YouTube,

i have home assistant supervised in debian docker, I configured mqtt with home assistant addon

and this is the user configuration

This worked for me. I came to the conclusion that my mqtt addon had the wrong user information. Updated that, and everything is working now!

I don’t know how many times the mosquitto addon docs and numerous forum posts need repeating, but here goes again:

Do not configure a user and pw in the addon

Configure a user in homeassistant. Settings|people|users.

The mosquitto addon will inherit the credentials from HA.

To show I’m not making it up, this is what the docs say (and which no-one seems to read)

Create a new user for MQTT via your Home Assistant’s frontend SettingsPeopleUsers , (i.e. not on Mosquitto’s Configuration tab). Notes:

  1. This name cannot be homeassistant or addons, those are reserved usernames.
  2. If you do not see the option to create a new user, ensure that Advanced Mode is enabled in your Home Assistant profile.
1 Like

Same problem here. I tried with and without users created in the addon. It is a fresh setup and I can’t work out what’s wrong. I precisely followed the doc.

Having the same problem…
Mosquitto broker log output:
error: received null username or password for unpwd check
2024-11-05 19:43:28: Client auto-63ADBDEA-F045-55C4-B319-F59330B20DF2 disconnected, not authorised.
2024-11-05 19:43:42: New connection from 172.30.32.2:32838 on port 1883.
2024-11-05 19:43:42: Client closed its connection.
2024-11-05 19:45:05: New connection from 192.168.0.209:61955 on port 1883.
2024-11-05 19:45:05: Client watermeter already connected, closing old connection.
2024-11-05 19:45:05: New client connected from 192.168.0.209:61955 as watermeter (p2, c1, k750, u’mqttuser’).
2024-11-05 19:45:28: New connection from 172.30.32.1:39896 on port 1883.
error: received null username or password for unpwd check
2024-11-05 19:45:28: Client auto-3843FB20-2A28-10EB-9047-FCF11C8D9FF4 disconnected, not authorised.
2024-11-05 19:45:42: New connection from 172.30.32.2:54048 on port 1883.
2024-11-05 19:45:42: Client closed its connection.
2024-11-05 19:47:28: New connection from 172.30.32.1:33712 on port 1883.
error: received null username or password for unpwd check
2024-11-05 19:47:28: Client auto-58AA068B-310A-C294-8367-1013BCE0E193 disconnected, not authorised.

Followed instructions on how to configure user.
AI on the edge - watermeter is operating ok but data is not coming in to Hassio.
What can I do to find the fault?
Thanks,