19

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:

  1. Disabling Windows defender
  2. Adding firewall rules for "mosquitto.exe"
  3. Installing mosquitto on a linux machine

First error

Second error

Netstat info

hardillb
  • 54,545
  • 11
  • 67
  • 105
FlasH
  • 193
  • 1
  • 1
  • 6
  • 1
    Please don't post images of text!! Just post the error text here. Secondly, this is a site for coding issues, and I see no code here at all....change it, or someone is going to come along and close down your post. – JD Allen Dec 13 '20 at 17:43

6 Answers6

30

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
listener 1883

More details can be found in the 2.0 release notes here

Peter
  • 37,042
  • 39
  • 142
  • 198
hardillb
  • 54,545
  • 11
  • 67
  • 105
  • Hello! Thank you for responding so quickly and fixing my post. I can't upvote your post, but if I could, I would. ;) I decided to not mess with the config file and just download an older version of mosquitto. If I had more time, I would delve into the config file and actually fix it that way. – FlasH Dec 13 '20 at 18:19
  • 2
    It really just the case of adding either `bind_interface device` or `bind_address ip_address` to the config file. – hardillb Dec 13 '20 at 18:37
  • 1
    @hardillb - this recent update has completely ruined my day - I've installed this via homebrew on mac osX, do you know what config file? – Adam Jenkins Dec 20 '20 at 16:17
  • It was a major version number change, so was expected to break things. I don't have a mac, so can only guess it might be under `/usr/local/etc` (as described in the log output you posted to your question) – hardillb Dec 20 '20 at 16:44
  • listener 1883 must be added as well – Randy Welt Dec 31 '22 at 17:19
  • @RandyWelt which is what the second paragraph makes clear – hardillb Dec 31 '22 at 17:31
19

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.)
anonymous
  • 191
  • 2
  • 2
    Thank you! Everywhere talks about defining a listener in the mosquitto.conf but this is the first I've come across needing to specify the file as an argument. – vincebel Dec 23 '21 at 16:13
18

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.

  1. On your Windows machine, run a text editor as administrator and paste the following text:
listener 1883
allow_anonymous true
  1. 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".

  2. 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.

derek t
  • 181
  • 1
  • 2
  • For some reason when I run like this I get an error stating mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf Gives Duplicate pid_file value in configuration & it doesn’t like line 6 & 13. Those two lines were included in the default conf file. Just pid_file snd include_dir. Have no idea what I’m still doing wrong. – Gallaugher Nov 20 '21 at 02:00
4

I found I had to add, not only bind_address ip_address but also had to set allow_anonymous true before devices could connect successfully to MQTT. Of course I understand that a better option would be to set user and password on each device. But that's a next step after everything actually works in the minimum configuration.

Viking
  • 63
  • 3
2

For those who use mosquitto with homebrew on Mac.


Adding these two lines to /opt/homebrew/Cellar/mosquitto/2.0.15/etc/mosquitto/mosquitto.conf fixed my issue.

allow_anonymous true 
listener 1883
veysel
  • 161
  • 1
  • 6
1

you can run it with the included 'no-auth' config file like so:

mosquitto -c /mosquitto-no-auth.conf 

I had the same problem while running it inside docker container (generated with docker-compose). In docker-compose.yml file this is done with:

command: mosquitto -c /mosquitto-no-auth.conf 
d.popov
  • 4,175
  • 1
  • 36
  • 47