Can only connect with MQTT default credentials

Hi,

Im trying to use the MQTT broker on my emonpi but am having trouble connecting. I can connect using the default credentials (emonpi emonpimqtt2016) but nothing else.

I’ve tried adding users and passwords to the correct password file but they get ‘not authorised’ messages when they try to connect and I’ve tried setting allow anonymous to True in the config but still, the only connection that can be made is the one using the default credentials.

I’m wanting to connect several arduino devices to the broker and assume (possibly incorrectly) that if all of them log in with the same credentials, something is going to go wrong somewhere…

Anyone know how I can
A) allow other users or even anonymous connections to the broker
B) configure it so that I don’t have to create a new user for each new device I want to connect to the broker

Thank you

When adding your own credentials are you using the correct commands rather than editing the files directly?

As seen in the mqtt section of the emonSD build guide

sudo mosquitto_passwd -c /etc/mosquitto/passwd emonpi

Alas, yes.

I just logged in and did the following;

rpi-rw
sudo nano /etc/mosquitto/passwd

There were 4 users in there, Pi, Emonpi, user1, user2. Each with their own encrypted password
I exited nano without making any changes. All 4 of those user could at this point connect to MQTT broker (don’t ask how I got these in there, I honestly don’t know).

I then did

sudo mosquitto_passwd -c /etc/mosquitto/passwd garage

setup a password and tried to connect but got a not authorised response.

So I used nano to look at the file again and the only user in there was the new garage one! Which couldn’t connect.

I then tried the other users that used to be in the password file. All the ones I had created no longer worked but the default emonpi emonmqtt2016 combination still did?!

Safe to say, I’m pretty confused by the whole thing

Appreciate any help you can give me

Cheers

I should add that I have just remembered how I added the other users; I ran your line of code without the -c to prevent it creating a new file and overriding the old one.

So I have now done this three times and created 3 users in the passwd file, which I can see when I use nano, each with its own encrypted password

But still, the only one that can connect is the default user?!

OK, so just for anyone else who is reading this, I think I’ve got it sussed.

Create a new password file using

sudo mosquitto_passwd -c /etc/mosquitto/passwd emonpi

Then use the default password emonpimqtt2016

If you want to add new users, use the same command but without the -c so it doesn’t create a new file each time.

Once you have added all the new users you want to, you need to restart the Mosquitto service for it to pickup the changes.

sudo mosquitto service stop
sudo mosquitto service start

When I did this, all the added users started working. No clue why the default user was connecting when it wasn’t in the passwd file, but hey, it was working so thats what matters.

Great result!

2 Likes

Thanks for sharing the solution Alun (@Bigalboyo)

Did you eventually allow anonymous connections to the broker?

Paul

Nice work @Bigalboyo :+1:

Just remove the line

allow_anonymous false

from /etc/mosquitto/mosquitto.conf

Then restart Mosquitto to allow anonymous connections.

If removing/changing the default user/password be aware that you will also need to change the credentials in:

  • emoncms settings.php
  • emonPiLCD script
  • emonhub
  • node-red
  • openhab