[Tutorial] Enviro+ with MQTT on DietPi

Guides and tutorials for various stuff. Posted by DietPi users.
Post Reply
Altmann
Posts: 1
Joined: Sun Jan 12, 2020 4:26 pm

[Tutorial] Enviro+ with MQTT on DietPi

Post by Altmann »

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.

Instructions

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

Code: Select all

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/

Code: Select all

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:

Code: Select all

[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 "<arguments>". I deleted this.
Once the correct User has been set, and the arguments are removed, I continued following the guide and set:

Code: Select all

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:

Code: Select all

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:
  • <prefix>/proximity
  • <prefix>/lux
  • <prefix>/temperature
  • <prefix>/pressure
  • <prefix>/humidity
  • <prefix>/gas/oxidising
  • <prefix>/gas/reducing
  • <prefix>/gas/nh3
  • <prefix>/particulate/1.0
  • <prefix>/particulate/2.5
  • <prefix>/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!
Ian
Posts: 11
Joined: Thu Feb 28, 2019 12:45 pm

Re: [Tutorial] Enviro+ with MQTT on DietPi

Post by Ian »

Hey thanks for this, extremely helpful.
Ian
Posts: 11
Joined: Thu Feb 28, 2019 12:45 pm

Re: [Tutorial] Enviro+ with MQTT on DietPi

Post by Ian »

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 "<arguments>". I deleted this." do you mean at the end of this line? "ExecStart=/usr/bin/python3 -u /usr/src/enviroplus-mqtt/src/main.py <arguments>", or the arguments themselves? How does one set them?

If not where does one store the arguments?

Thanks
Post Reply