mosquitto-client obtain refused connection
For future googlers:
You can use a public host as mentioned above, but to start a local mosquitto broker, first make sure you have installed mosquitto
in addition to mosquitto_sub
. You can then start up the mosquitto broker by simply running the following:
mosquitto
Just edit Mosquitto configuration file ( /etc/mosquitto/conf.d/mosquitto.conf
) adding these lines...allow_anonymous true
listener 1883 0.0.0.0
... and restart Mosquitto (as service or not).$ sudo service mosquitto restart
or$ mosquitto --verbose --config-file /etc/mosquitto/conf.d/mosquitto.conf
As informed here, since v.1.7 allow_anonymous
defaulted to false.
It is also useful to check log messages ( /var/log/mosquitto/mosquitto.log
).
Finally, run Mosquitto subscriber/publisher using --host
(-h
) parameter and the host IP address (get if from ifconfig
or ip -color addr
command).
None of the other answers worked for me. In my case, I had upgraded from mosquitto 1.X to mosquitto 2.0, which requires a new configuration to be added to your mosquitto.conf
:
listener 1883
For clients other than localhost to connect (ie, via Docker)
The default host:port combination for mosquitto_pub/sub is localhost:1883. If you do not have a broker running on your local computer then it will not be able to connect of course.
The solution is to either run the broker on your local computer, or to tell the utilities where to connect. For example:
mosquitto_sub -t newtopic/test -h test.mosquitto.org