I have a virtual machine that is supposed to be the host, which can receive and send data. The first picture is the error that I'm getting on my main machine (from which I'm trying to send data from). The second picture is the mosquitto log on my virtual machine. Also I'm using the default config, which as far as I know can't cause these problems, at least from what I have seen from other examples. I have very little understanding on how all of this works, so any help is appreciated.
What I have tried on the host machine:
The default configuration file is called mosquitto. conf and it is used by the mosquitto broker when started as a Linux daemon or Windows service. You will find the mosquitto. conf file in the /etc/mosquitto directory on Linux, and in the c:\mosquitto\ directory on Windows.
Install the Mosquitto utilities for your operating system. Create a config file named mosquitto. conf for the broker with the following contents. To start a broker that requires clients to authenticate using a username and password, change allow_anonymous to false and add password_file /etc/mosquitto/passwd .
Starting Mosquitto on Windows To start the broker manually open a command prompt and go to the mosquitto install directory and type mosquitto.
On Windows you can stop the service if it is running by using the control panel>admin>services. By default the broker will start listening on port 1883.
By default, the Mosquitto broker will only accept connections from clients on the local machine (the server hosting the broker). Therefore, a custom configuration needs to be used with your instance of Mosquitto in order to accept connections from remote clients.
listener 1883
allow_anonymous true
This creates a listener on port 1883 and allows anonymous connections. By default the number of connections is infinite. Save the file to "C:\Program Files\Mosquitto" using a file name with the ".conf" extension such as "your_conf_file.conf".
Open a terminal window and navigate to the mosquitto directory. Run the following command:
mosquitto -v -c your_conf_file.conf
where
-c : specify the broker config file.
-v : verbose mode - enable all logging types. This overrides any logging options given in the config file.
You have to run with
mosquitto -c mosquitto.conf
mosquitto.conf, which exists in the folder same with execution file exists (C:\Program Files\mosquitto etc.), have to include following line.
listener 1883 ip_address_of_the_machine(192.168.1.1 etc.)
Starting with the release of Mosquitto version 2.0.0 (you are running v2.0.2) the default config will only bind to localhost
as a move to a more secure default posture.
If you want to be able to access the broker from other machines you will need to explicitly edit the config files to either add a new listener
that binds to the external IP address (or 0.0.0.0) or add a bind
entry for the default listener.
By default it will also only allow anonymous connections (without username/password) from localhost, to allow anonymous from remote add:
allow_anonymous true
More details can be found in the 2.0 release notes here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With