Problem with Mosquitto starting in Local mode

I have a problem with mqtt on a new Emoncms installation. e.g.

mosquitto_pub -t 'emon/4/Solar' -m 123 → works ok (executed on the same machine)
mosquitto_pub -h 'pegasus2' -u 'emonpi' -P 'emonpimqtt2016' -t 'emon/4/Solar' -m 345 → Error: Connection refused (when executed either on the same machine or a different pi on the same network).

I tried adding new credentials to passwd using sudo mosquitto_passwd -b passwd pub_client '<different password>' but I still get the same response when I try to use -h.
No problems on my (very old) Emoncms installation - it has no password set!
Found a couple of postings on the forum and tried mosquitto -d command and deleting the mosquitto log but still no joy. Everything else looks normal.

Did I miss something in the install? Any thoughts?
Thanks in advance.

Raspberry Pi 3
Raspberry Pi OS with desktop
Release date: May 3rd 2023
System: 64-bit
Kernel version: 6.1
Debian version: 11 (bullseye)

EMONCMS DIY BUILD using the installation script at EmonCMS Install Scripts (reports Emoncms low-write 11.3.20)
In config.ini:
NO emonhub so changed:

and commented out:
declare -A emoncms_emonpi_modules i.e. #declare -A emoncms_emonpi_modules

Not sure what hostname=emonpi is or is used for. The pi hostname was set as Pegasus2 during the OS installation. In config.ini I’ve tried hostname=emonpi and hostname=Pegasus2

/etc/mosquitto/mosquitto.conf includes:
allow_anonymous false
password_file /etc/mosquitto/passwd

How did you do the install, and on what OS?


That isn’t correct (Mosquitto Username and Password Authentication -Configuration and Testing)

mosquitto_passwd -b passwordfile user password

Try deleting the users and redoing them.

I don’t think you should quote the user and password elements so,

mosquitto_pub -h 192.168.x.x -u emonpi -P emonpimqtt2016

I think the host is the issue

Can you ping that host? If not Mosquitto has no hope of connecting! Nothing to do with passwords.

Brian, thanks so much for your reply.

I recall (amongst many other things) I had already tried your suggestion after I reading Steve’s Internet Guide but may have got confused about the combination of settings and their ordering in mosquitto.conf (as described here: per_listener_settings true)

Having done a new trial build of Emoncms last night, I looked at the problem again and I stumbled across a mqtt start up message mentioning ‘starting in local mode only’. It seems that this is the default for my new version of mqtt:
mosquitto version 2.0.11
mosquitto is an MQTT v5.0/v3.1.1/v3.1 broker.

My old (current) version is:
mosquitto version 1.4.10 (build date Tue, 26 Oct 2021 22:24:15 +0200)
mosquitto is an MQTT v3.1 broker.

Adding listener 1883 to mosquitto.conf enables access from remote clients. The following combination of settings in mosquitto.conf now works for me (yeah!).

allow_anonymous false
listener 1883
password_file /etc/mosquitto/passwd

However, my intention for moving from a ‘no password’ to a ‘password’ implementation was to improve security. I’m not sure whether or not including listener 1883 compromises that intention (hmm!).

The password I had added to the password file started with an exclamation mark which seemed to upset mqtt:
-bash: !xyz: event not found
So I put it in quotes - that seemed to solve that problem. The mqtt cli seems to work with or without quotes.

By the way (sorry this is a bit off topic) the Emoncms (OpenEnergyMonitor) install script config.ini includes install_mosquitto_client=true however I don’t believe it does that install. I had to install this separately in order to use client commands.

That is interesting. I’m running that version and it doesn’t need that. Cannot see that the package installer has been updated, either.

[email protected]:/var/log/mosquitto $ journalctl -u mosquitto
-- Journal begins at Wed 2023-05-17 11:11:05 BST, ends at Wed 2023-05-17 11:14:12 BST. --
May 17 11:11:42 emonpi systemd[1]: Stopping Mosquitto MQTT Broker...
May 17 11:11:43 emonpi systemd[1]: mosquitto.service: Succeeded.
May 17 11:11:43 emonpi systemd[1]: Stopped Mosquitto MQTT Broker.
May 17 11:11:43 emonpi systemd[1]: mosquitto.service: Consumed 3h 30min 22.081s CPU time.
May 17 11:11:43 emonpi systemd[1]: Starting Mosquitto MQTT Broker...
May 17 11:11:43 emonpi systemd[1]: Started Mosquitto MQTT Broker.

Poorly worded. That isn’t the package mosquitto-clients it is the emoncms PHP MQTT Client (the bit that reads data from the Broker and imports it to emoncms).

It is interesting @glyn.hudson @TrystanLea that this has not been raised before. Seems it was introduced with V2 of the package.

I just noticed this (bit slow today)

The scripts are tested on the 32Bit OS lite package - not the 64bit Desktop base (as per the documentation).

That is probably where your issues stemmed from. Last time I tried the 64bit image I had other problems with PHP (but they might be solved by other work on installing PHP).