Air Quality
The project aims at building an air quality measurement station. The steps are mostly based on the blog post, but shall be extended/modified in two respects:
- Explain the initial setup of a headless raspian on a new Raspberry Pi Zero W
- Store the information in Google Cloud
As a result a moderate technically interested person should be able to replicate the steps under supervision when having all hardware available.
For making fast progress we will avoid connecting the Rasperry Pi with a keyboard and a monitor, but instead use a headless setup (headless basically means without keyboard and monitor). This setup presents us with two challenges if we use a fresh raspbian image for the SD card:
- The Wifi connection is not enabled: The Raspberry Pi don't know how to connect to your WiFi.
- SSH is not enabled: We will use SSH to connect to the Raspberry Pi and continue the setup.
The next steps are based on vorillaz' blog post and the Raspberry Pi installation documentation:
- Download the image from the Raspberry Pi downloads page: We will use Raspbian Lite image.
- Writing an image to the SD card: In this example I have used balenaEtcher for Windows
Due to issue 3184 the wifi configuration doesn't work on the newest release for some configurations. wpasupplicant needs to be downgraded. For the built-in Wifi module a downgrade finally was not required, but adjusting the wpa_supplicant.conf file did the trick. Before the network declaration add the following 3 lines:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=PL
Rasbpian Lite doesn't include the pacNot all Python packages are available in the Raspbian archives, and those that are can sometimes be out-of-date. If you can't find a suitable version in the Raspbian archives, you can install packages from the Python Package Index (PyPI). To do so, use the pip tool.
pip is installed by default in Raspbian Desktop images (but not Raspbian Lite). You can install it with apt:
sudo apt-get install python3-pip
git clone https://github.com/matzie5/airq
cd airq
Make sure the required core packages are all installed
chmod +x initialsoftware.sh
./initialsoftware.sh
In order to communicate with Google Cloud, a security certificate must be generated and then registered with IoT core.
chmod +x generate_keys.sh
./generate_keys.sh
After the certificate has been created you can copy it to your localhost into the current folder:
scp [email protected]:/home/pi/.ssh/ec_public.pem .
If you aren't in the /home/pi/airq directory on the Raspberry Pi, move there first
cd /home/pi/airq
Start the heart rate script by changing the following to match your project, registry and device
python airquality.py --project_id=myproject --registry_id=myregistry --device_id=mydevice
e.g.
python airquality.py --project_id=iot-airquality --registry_id=airquality --device_id=zienerAirQ
You should see the terminal window echo the airquality about every 10 seconds. With data flowing, you can skip to the next section.
In the standard configuration we are using the USB port to control the device. We can take a shortcut here and connect the device directly to the serial port on the GPIO pins. For this step we need to enable UART on the raspberry pi:
sudo echo "enable_uart=1" >> /boot/config.txt
sudo nano /boot/cmdline.txt
# Remove `console=serial0,115200`
# Restart for changes to take effect
sudo shutdown -r now