Enviro+ mqtt-all.py

Hello,

I’ve successfully installed everything on a RPi Zero W. Run python combined.py and all displays fine.

When I try to run mqtt-all.py I get an error:

File “mqtt-all.py”, line 184
“”"
^
SyntaxError: invalid syntax

Could someone give some advice please?

Regards
Ian

mqtt-all.py uses Python f-strings, which IIRC were introduced in Python 3.6. Are you using Python 2 to run your scripts?

Thanks,

I just installed everything so I assumed it would be the latest version, but on checking I have both 2.7.16 and 3.73 installed

Is possible to just delete Python 2 or force it to use Python 3?

How are you running mqtt-all.py? The comment at the top of that file says, in part:

Example run: python3 mqtt-all.py --broker 192.168.1.164 --topic enviro

If you made it executable, and are therefore running it as ./mqtt-all.py, then adding the following line at the top of the file should do it:

#!/usr/bin/env python3

Sorry I’m quite new to Python and I just used

python mqtt-all.py

in the examples folder.

I just run the example script you mentioned and got a Connection Refused error:

python3 mqtt-all.py --broker 192.168.0.25 --topic enviro
mqtt-all.py - Reads Enviro plus data and sends over mqtt.

broker: 192.168.0.25
client_id: raspi-0000000098c21c23
port: 1883
topic: enviro

Press Ctrl+C to exit!

Traceback (most recent call last):
File “mqtt-all.py”, line 238, in
main()
File “mqtt-all.py”, line 190, in main
mqtt_client.connect(args.broker, port=args.port)
File “/usr/local/lib/python3.7/dist-packages/paho_mqtt-1.5.1-py3.7.egg/paho/mqtt/client.py”, line 941, in connect
return self.reconnect()
File “/usr/local/lib/python3.7/dist-packages/paho_mqtt-1.5.1-py3.7.egg/paho/mqtt/client.py”, line 1075, in reconnect
sock = self._create_socket_connection()
File “/usr/local/lib/python3.7/dist-packages/paho_mqtt-1.5.1-py3.7.egg/paho/mqtt/client.py”, line 3546, in _create_socket_connection
return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
File “/usr/lib/python3.7/socket.py”, line 727, in create_connection
raise err
File “/usr/lib/python3.7/socket.py”, line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Done it!!

mosquitto wasn’t installed!

Now I’ll do as you suggested, make it executable and run on boot

Thanks