mosquitto MQTT ConnectionRefusedError: [Errno 111] Connectio

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
gallaugher
 
Posts: 267
Joined: Tue Aug 14, 2018 12:42 pm

mosquitto MQTT ConnectionRefusedError: [Errno 111] Connectio

Post by gallaugher »

Anyone with experience with mosquitto / paho mqtt on the Raspberry Pi? I've used this to send commands to the Pi to do things like play sounds & move a robot, but for some reason on my new Pi with Bullseye installed, I can't seem to get a connection to work with the same code.
Sample code below runs on old setup, but with current / fresh setup I get:
ConnectionRefusedError: [Errno 111] Connection refused

I havre a mosquotto broker & the client code running on the same computer. FWIW when I run the sample two-window hello-world test code (below) all works. Unsure why the connection code isn't working.
Terminal window 1:

Code: Select all

mosquitto_sub -d -t testTopic
Terminal window 2:

Code: Select all

mosquitto_pub -d -t testTopic -m "Hello world!"
Hello world! prints in Terminal window 1, as expected.

Here is the python code that's generating the error (but doesn't generate the error on an install done earlier this year w/a January-ish Raspberry Pi OS & paho / mosquitto)
https://gist.github.com/gallaugher/65f8 ... 8de756a17e

Output below:

Code: Select all

Traceback (most recent call last):
  File "/home/pi/control-pibot.py", line 119, in <module>
    mqttClient.connect(serverAddress)
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 914, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 1044, in reconnect
    sock = self._create_socket_connection()
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
    return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
Thx for any advice!

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: mosquitto MQTT ConnectionRefusedError: [Errno 111] Conne

Post by mikeysklar »

Code: Select all

listener 1883
allow_anonymous true
Add the above to your mosquitto configuration.

via https://forums.raspberrypi.com/viewtopic.php?t=324145

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”