Skip to content

Gman1988/airq

 
 

Repository files navigation

airq

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.

Raspberry Pi Zero W - Headless Setup

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:

Buster Wifi Bug on Raspberry Pi Zero W

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

Install pip

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

Prepare for Cloud connection

git clone https://github.com/matzie5/airq
cd airq

Make sure the required core packages are all installed

chmod +x initialsoftware.sh
./initialsoftware.sh

Create a security certificate

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 pi@192.168.1.29:/home/pi/.ssh/ec_public.pem .

Run the program

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.

Modify the program

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

Releases

No releases published

Packages

No packages published

Languages

  • Python 90.8%
  • Shell 9.2%