Raspberry Pi 3b Enviroplus MQTT connection Time Out

Hey everyone

Been having a lot of difficulty getting my Enviroplus and Particulate sensor sending data over MQTT with the mqtt_all.py program. The other examples are running well on my Raspberry Pi 3b and the data is showing on the Enviroplus Web App.

I have the MQTT broker working on the Pi, and tested it is operational.

When trying to run mqtt-all with the necessary arguments I get a Time out error below. No data is getting to the Broker. Ultimately I want to connect into Home Assistance but first step is getting the data into the Broker, I think.

I did read there was version issue with paho mqtt so I did rollback the version as mentioned here but now getting this timeout error instead of an API error. python - Paho MQTT 'Unsupported callback API version' error - Stack Overflow

Anyway, heres the command to run mqtt_all.py followed by the resulting error

kavanaa1@raspberrypi3b:~/Pimoroni/enviroplus/examples $ python3 mqtt-all.py --broker 192.162.210 --topic enviroplus --interval 5
mqtt-all.py - Reads Enviro plus data and sends over mqtt.

broker: 192.162.210
client_id: raspi-000000008999ab6e
port: 1883
topic: enviroplus
tls: False
username: None
password: None

Press Ctrl+C to exit!

Traceback (most recent call last):
File “/home/kavanaa1/Pimoroni/enviroplus/examples/mqtt-all.py”, line 278, in
main()
File “/home/kavanaa1/Pimoroni/enviroplus/examples/mqtt-all.py”, line 225, in main
mqtt_client.connect(args.broker, port=args.port)
File “/home/kavanaa1/.local/lib/python3.9/site-packages/paho/mqtt/client.py”, line 914, in connect
return self.reconnect()
File “/home/kavanaa1/.local/lib/python3.9/site-packages/paho/mqtt/client.py”, line 1044, in reconnect
sock = self._create_socket_connection()
File “/home/kavanaa1/.local/lib/python3.9/site-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)
socket.timeout: timed out

Any and all help gratefully accepted !

Is the broker address correct? I don’t believe that broker: 192.162.210 is a valid IP address. There’s also no username or password set.

Your broker’s hostname could also be used for example mqttbroker.local:portnumber this would get around any dynamic IP addressing issues.

Or is this intentional?

Yeah, that doesn’t look right?
192.168.2.210 maybe?

Yikes, you are correct the IP address should have been 192.168.2.10, I apologise.

Now getting a Refused error as opposed to a Timeout error. Not sure if that is better!

kavanaa1@raspberrypi3b:~/Pimoroni/enviroplus/examples $ python3 mqtt-all.py --broker 192.168.2.10 --topic enviro
mqtt-all.py - Reads Enviro plus data and sends over mqtt.

broker: 192.168.2.10
client_id: raspi-000000008999ab6e
port: 1883
topic: enviro
tls: False
username: None
password: None

Press Ctrl+C to exit!

Traceback (most recent call last):
File “/home/kavanaa1/Pimoroni/enviroplus/examples/mqtt-all.py”, line 278, in
main()
File “/home/kavanaa1/Pimoroni/enviroplus/examples/mqtt-all.py”, line 225, in main
mqtt_client.connect(args.broker, port=args.port)
File “/home/kavanaa1/.local/lib/python3.9/site-packages/paho/mqtt/client.py”, line 914, in connect
return self.reconnect()
File “/home/kavanaa1/.local/lib/python3.9/site-packages/paho/mqtt/client.py”, line 1044, in reconnect
sock = self._create_socket_connection()
File “/home/kavanaa1/.local/lib/python3.9/site-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

Connection refused is better than timeout - it tells you the port is up and running but the broker does not let you in. As @fishgotnosole pointed out, you did not set a username/password. That could be the cause.

1 Like

I’m fairly sure that a socket-level ‘connection refused’ indicates that the IP address is up, but there’s nothing listen on the port - a username/password failure would be app-level.

So… I’d say either your broker isn’t running, or it isn’t running on that port.

Or (and I say this as someone who does this far too often) you’ve still your the IP address wrong, and you’re currently trying to MQTT into your printer :-)

Yes, true. Forget my last post.