I am far from being a computer network specialist, but I learn a little bit at a time.
My goal is to dialogue between Arduino with MQTT via Mosquitto installed on a raspberry.
But if it works in localhost, this is not the case in the local network like for example with ‘MQTT Explorer’ on Windows or connection sketches in Arduino.
No way connect to the server. I disabled the firewall of the Asus RT-AC88u router and I do my Ethernet tests.
I installed it on another PI ‘virgin’ and I have the same problem.
It’s been a week that I turn around and lots of tutorials seem to copy each other but without examples or clear explanations.
Not to mention that I do not control English and that translators are sometimes approximate in the technical fields …
I’m sorry to hear you’re having problems. I’m sure we can sort them out.
From Mosquitto version 2.0 onwards some of the way the broker works changed, which is why the tutorials you are looking at may miss some steps out I imagine.
If you run Mosquitto without a configuration file then it will allow unauthenticated access but on localhost only. The same is true if you have a configuration file but do not define a listener.
If you want to allow connections from other computers, you must define a listener and define some form of authentication. That could be password file based authentication, the dynamic security plugin, or allowing unauthenticated access with the allow_anonymous true option.
Once you’ve done one of those, the broker should work as you expect.
# Dynamic security plugin
# Note that the paths may be different on your system
# Use mosquitto_ctrl or the Management Center to control the plugin
listener 1883
plugin /usr/lib/mosquitto_dynamic_security.so
plugin_opt_config_file /var/lib/mosquitto/dynamic-security.json
# Password and Access Control List file
# Use mosquitto_passwd to manage the password file
listener 1883
password_file /etc/mosquitto/passwd
acl_file /etc/mosquitto/acl
Let me know if that works or if you need more help.
Hello,
Yes, another forum gave me a track and I understood the problem by visualizing the log. (“local only mode” …)
sudo tail -f /var/log/mosquitto/mosquitto.log | tee /var/tmp/mosquitto.log
1629960276: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1629960276: mosquitto version 2.0.11 starting
1629960276: Config loaded from /etc/mosquitto/mosquitto.conf.
1629960276: Starting in local only mode. Connections will only be possible from clients running on this machine.
1629960276: Create a configuration file which defines a listener to allow remote access.
1629960276: For more details see https://mosquitto.org/documentation/authentication-methods/
1629960276: Opening ipv4 listen socket on port 1883.
1629960276: Opening ipv6 listen socket on port 1883.
1629960276: mosquitto version 2.0.11 running
1629962076: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
Sure enough, with trial and error, I modified the configuration file, and it works by adding the lines as you have also suggested in your reply.
Additional information. No matter where I place my Mosquitto.conf file the command Mosquitto -v always states it is using a default configuration file. I did try putting the file in /etc/mosquitto/config.d.
When you run mosquitto -v then that won’t load any configuration file. You need to use mosquitto -c <path to config file>. The package installation assumes you will be using the built in service management tools for running mosquitto (sudo systemctl start mosquitto) which uses the configuration files already. So either try running manually with -c, or use systemctl to start or restart the current running instance.
After editing the conf file I did a systeemctl restart and the log showed it was reading the config changes and not the default. Seems to be working even after a power down restart. Thanks for your help.
Per @roger.light suggestion, when I enter mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf
I get the following:
Loading config file /etc/mosquitto/conf.d/mosquitto.conf
Error: Duplicate pid _file value in configuration
Error found at /etc/mosquitto/conf.d/mosquitto.conf:8
Error found at /etc/mosquitto/conf.d/mosquitto.conf:15
Here are some pics of my conf file and directory. Am sure I am 98% there.