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
Code: Select all
mosquitto_pub -d -t testTopic -m "Hello world!"
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