Hi Sara, I am going through the eBook Smart Home RPi & ESP32 and am stuck at the Mosquitto install/test section. I installed it and did the test with 2 terminals, and got the proper results. Then I implemented the security feature (i.e. user and password), and found I could still do the test (it didn’t complain about errors). Then I did something – I don’t know what – and then couldn’t get mosquitto to restart. So, as per another blogger’s question/answer, I removed mosquitto (i.e. sudo apt remove mosquitto mosquitto-clients), and afterwards get -bash: mosquitto: command not found, which is what one would expect. Then I reinstalled (i.e. sudo apt install – y mosquitto mosquitto-clients), and did sudo systemctl enable mosquitto.service, then tried mosquitto -v and get
1672954368: mosquitto version 1.5.7 starting
1672954368: Using default config.
1672954368: Opening ipv4 listen socket on port 1883.
1672954368: Opening ipv6 listen socket on port 1883.
(it hangs there, then eventually states ^C1672954471: mosquitto version 1.5.7 terminating).
When I open another terminal, and do mosquitto_sub -d -t testTopic, I get: Error: Connection refused
I tried sudo reboot, and again the mosquitto_sub -d -t testTopic … with the same result. Trying sudo systemctl enable mosquitto.service then the mosquitto_sub -d -t testTopic …. again Error: Connection refused
Any idea why I can’t do the test again ? … I deleted the password file, and removed any new stuff in the .config file – doesn’t help. Thanks for any advice. — JoeM
Hi.
I’m not sure what might be the issue.
How does you configuration file look like?
Regards,
Sara
Hi Sara … I figured it out. The bottom line is that the allow_anonymous false statement causes the connection error. When I commented that out, it worked fine, including requiring the username/password to do the testTopic.
I also had another issue: there was a mosquitto.conf file in /etc/mosquitto/conf.d directory which is not purged (or removed) by the sudo apt remove mosquitto command, and even though I removed all the “extra stuff” the eBook states for when authentication is implemented, the /etc/mosquitto/mosquitto.conf file states that things can be found in the /etc/mosquitto/conf.d directory (which still had the modified mosquitto.conf file).
Anyway. I’m not perfectly clear why the allow_anonymous false statement causes the connection error… the man pages for mosquitto.conf state the following:
allow_anonymous [ true | false ]
Boolean value that determines whether clients that connect without providing a username are allowed to connect.
If set to false then another means of connection should be created to control authenticated client access.
Defaults to true if no other security options are set.
If any other authentication options are set, then allow_anonymous defaults to false.
“Boolean value that determines whether clients that connect without providing a username are allowed to connect” would seem to imply making it false when a password file is present ….
Anyway, all is well now. this can be closed