Difficulty: 3/5, Time Needed: ~60 min
Got the new Air Quality Kit for Raspberry Pi? Let’s get started!
Make an air quality monitoring device with your Raspberry Pi and two sensors which will measure eCO2 (Carbon dioxide equivalent), VOC (Total Volatile Organic Compounds), Temperature and Humidity. All of this data will be sent to OKdo Cloud and you’ll be able to check it (current and historical) using your web browser or your smartphone. Let’s go:
You’ll need to create the device on OKdo Cloud so you can use your Raspberry Pi to send data from its sensors to it.
You’ll have a default “Playground” ground if you’ve just created your account
Assets TVOC, eCO2, Temperature and Humidity are already present and your Raspberry Pi will send sensor data to them.
Make sure to use the included spacers and screws - it’ll be more stable
You can use any digital port, but be sure to change the pin in the code later
Flashing the OS
In this step, you’ll flash the operating system for your Raspberry Pi so you can start working in it.
- This is the “Lite” version of the OS, which means it doesn’t have a graphical user interface - it only has command line, which is good since you’re going to run the Raspberry Pi headless (without monitor/keyboard/mouse)
If you already have a system installed, please make sure it’s at least Raspbian Buster because older Raspbians (e.g. Stretch) will need additional steps of upgrading python and a few other things.
You’ll see a lot of command line output on your monitor. Once you see “raspberry pi login:”, you can continue with the steps below
Initial System Configuration
Now you’ll configure the Raspberry Pi so that you have a functional system ready to be used without a monitor or a keyboard.
pi
(default user) and then enter raspberry
(default password). You’re now logged in to your Raspberry Pisudo raspi-config
to enter the Raspberry Pi software configuration toolThis is important - leaving the default password on an SSH-enabled system is a security risk
pi
as user and your new passwordifconfig
and make note of your IP Address (should be under network interface “wlan0” as “inet X.X.X.X”)In case you’re using a Linux or macOS machine, open terminal and execute
ssh pi@your_ip_address
and you’ll be prompted to enter the user and password
Script Installation
This is the part where you’ll actually read and send data from your sensors!
sudo apt-get install python-pip python3-pip
Installs “pip”, which is a Python package installer. Enter “y” when asked to confirm installation.
curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
Installs “grove.py”, a dependency for sensor libraries
sudo pip3 install allthingstalk seeed-python-dht seeed-python-sgp30
Installs the library for communicating with OKdo, Temperature & Humidity Sensor and the VOC and eCO2 (SGP30) Sensor
sudo nano /usr/bin/okdo_airquality.py
1 | #!/usr/bin/env python3 |
DEVICE_ID
variable to contain your device IDTo get your Device ID, on OKdo Cloud, go to your Device > Settings > Authentication > Device ID
DEVICE_TOKEN
variable to contain your device tokenTo get your Device ID, on OKdo Cloud, go to your Device > Settings > Authentication > Device Tokens
DHT_PIN
variable to your pin number.python3 /usr/bin/okdo_airquality.py
The sensor data is printed out in your terminal and sent to your OKdo Cloud every 30 seconds.
Script Auto-Start
Now you’ll make the system take care of the script, so it makes sure it:
You’ll do that by adding the script as a service in the “systemd” directory:
sudo nano /etc/systemd/system/okdo_airquality.service
1 | [Unit] |
Press CTRL+X, Confirm with “y” and confirm the name.
sudo chmod +x /usr/bin/okdo_airquality.py
- Adds permissionssudo systemctl daemon-reload
- Reloads servicessudo systemctl start okdo_airquality
- Starts our scriptsudo systemctl enable okdo_airquality
- Enables our script to start at bootsudo systemctl status okdo_airquality
- Check the status.Active: active (running)
And use
sudo systemctl stop okdo_airquality
if you want to stop the service, orsudo systemctl disable okdo_airquality
if you wish to stop it from being executed at boot.
You now have a fully functional air quality measuring device!
Let’s do the final stuff to make it look nice.
Make the data more presentable by creating a Pinboard to show it all:
You can also rearrange and change control’s size, so you can get something like this:
Help others be aware of air quality in your area by sharing your data with the OKdo Air Quality Community:
Click “+ New Asset” and fill it out as shown:
Set your Location by clicking the location asset, and click Use my location
, or choose your location on a map (does not have to be precise if you’re not comfortable with it).
Enjoy your new Air Quality device!