[Tutorial] Enviro+ with MQTT on DietPi

Wanted to share the steps I took to get Enviro+ with MQTT working on DietPi with a Raspberry Pi 0 W. I started with a minimal DietPi setup with no optional software installed and with sudo apt update && sudo apt upgrade done.


# Pre-requisites (not sure if all are needed, these are the ones I used)

su -
apt install python-numpy python3-numpy
apt install python-smbus python3-smbus
apt install python-setuptools python3-setuptools
apt install build-essential
apt install gdb-multiarch
apt install python-dev
apt install python-pip python3-pip
apt install python-pil python3-pil
pip install wheel && pip3 install wheel && pip install spidev && pip3 install spidev
pip install requests && pip3 install requests
pip install RPi.GPIO && pip3 install RPi.GPIO

# Edit the DietPi config.txt file to enabe I2C and SPI, disable serial terminal, and to add the dtoverlay at the end.

  • Line 72: dtparam=i2c_arm=on
  • Line 73: dtparam=i2c1=on
  • Line 76: dtparam=spi=on
  • Line 81: enable_uart=1 (make sure that serial console is off)
  • Line 99: dtoverlay=pi3-miniuart-bt

# Install enviro+, hotplot’s Enviro+ MQTT logger, and the example files from Pimoroni to /usr/src/

pip install enviroplus && pip3 install enviroplus
apt install git
git clone https://github.com/hotplot/enviroplus-mqtt /usr/src/enviroplus-mqtt
git clone https://github.com/pimoroni/enviroplus-python /usr/src/enviroplus

With the above, the Enviro+ board should world fine. Try it with: python /usr/src/enviroplus/examples/*.py. Note: I could only get the PMS5003 sensor working if I first ran luftdaten.py (probably an easy fix).

Running the sensor board and posting values over MQTT

For hotplot’s logger to work, you’ll need paho-mqtt (pip3 install paho-mqtt) and to set up a MQTT broker (I tested with both localhost and a broker on another device). You will also need to follow the guide from step 5 with some minor changes:

Description=Enviro+ MQTT Logger

ExecStart=/usr/bin/python3 -u /usr/src/enviroplus-mqtt/src/main.py <arguments>


  • Note that the “User” is set to “pi”. Change this to your user (mine was root).
  • Note the “”. I deleted this.

Once the correct User has been set, and the arguments are removed, I continued following the guide and set:

sudo systemctl enable envlogger.service
sudo systemctl start envlogger.service

I rebooted for good measure. Once I rebooted, all the sensors worked and I could send values over MQTT with:

python3 /usr/src/enviroplus-mqtt/src/main.py -h localhost --use-pms5003

Topics to subscribe to using MQTT are listed on hotplot’s github repository and include:

  • /proximity
  • /lux
  • /temperature
  • /pressure
  • /humidity
  • /gas/oxidising
  • /gas/reducing
  • /gas/nh3
  • /particulate/1.0
  • /particulate/2.5
  • /particulate/10.0

Check out the PMS5003 Pimoroni page for some helpful information, the PMS5003 datasheet for more info about the sensor, and this link on how to interpret the values.

Hope it helps!

Hey thanks for this, extremely helpful.

Could you help me from “Running the sensor board and posting values over MQTT” in your instructions, I’m a little confused about what do after that.

when you say “Note the “”. I deleted this.” do you mean at the end of this line? "ExecStart=/usr/bin/python3 -u /usr/src/enviroplus-mqtt/src/main.py ", or the arguments themselves? How does one set them?

If not where does one store the arguments?