# \[Tutorial\] Enviro+ with MQTT on DietPi

**URL:** <https://dietpi.com/forum/t/tutorial-enviro-with-mqtt-on-dietpi/3745>\
**Category:** Community Tutorials\
**Created:** [12 January 2020 16:26 UTC](https://dietpi.com/forum/t/tutorial-enviro-with-mqtt-on-dietpi/3745 "2020-01-12T16:26:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Altmann](https://dietpi.com/forum/letter_avatar_proxy/v4/letter/a/eb9ed0/32.png) [@Altmann](https://dietpi.com/forum/u/Altmann)\
**Post date:** [12 January 2020 16:26 UTC](https://dietpi.com/forum/t/tutorial-enviro-with-mqtt-on-dietpi/3745/1 "2020-01-12T16:26:41Z")

</div>

Wanted to share the steps I took to get [Enviro+](https://shop.pimoroni.com/products/enviro?variant=31155658457171) 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.

Instructions

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

```nohighlight
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/**

```nohighlight
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](https://github.com/hotplot/enviroplus-mqtt#setting-up-your-device) with some minor changes:

```nohighlight
[Unit]
Description=Enviro+ MQTT Logger
After=network.target

[Service]
ExecStart=/usr/bin/python3 -u /usr/src/enviroplus-mqtt/src/main.py <arguments>
WorkingDirectory=/usr/src/enviroplus-mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

```

- 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:

```nohighlight
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:

```nohighlight
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](https://github.com/hotplot/enviroplus-mqtt#published-topics) 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](https://shop.pimoroni.com/products/pms5003-particulate-matter-sensor-with-cable) for some helpful information, the [PMS5003 datasheet](http://www.aqmd.gov/docs/default-source/aq-spec/resources-page/plantower-pms5003-manual_v2-3.pdf) for more info about the sensor, and [this link](https://publiclab.org/questions/samr/04-07-2019/how-to-interpret-pms5003-sensor-values) on how to interpret the values.

Hope it helps!

---

<div class="post-metadata">

**Author:** ![Ian](https://dietpi.com/forum/user_avatar/dietpi.com/ian/32/1872_2.png) [@Ian](https://dietpi.com/forum/u/Ian)\
**Post date:** [2 February 2020 19:42 UTC](https://dietpi.com/forum/t/tutorial-enviro-with-mqtt-on-dietpi/3745/2 "2020-02-02T19:42:23Z")

</div>

Hey thanks for this, extremely helpful.

---

<div class="post-metadata">

**Author:** ![Ian](https://dietpi.com/forum/user_avatar/dietpi.com/ian/32/1872_2.png) [@Ian](https://dietpi.com/forum/u/Ian)\
**Post date:** [4 February 2020 17:52 UTC](https://dietpi.com/forum/t/tutorial-enviro-with-mqtt-on-dietpi/3745/3 "2020-02-04T17:52:48Z")

</div>

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?

Thanks
