Born of necessity, this project tracks the air quality over Sydney during the height of the Australian bush fires. I wanted to gauge when it was safe to go outside, or when it was better to close up the apartment and stay in for the day.
| Sydney, Dec 2019 | Particulate matter readings |
|---|---|
![]() |
Readings for PM 2.5 and PM 10 approx 1000. Healthy levels should be between 0 ~ 10. ![]() |
This is Sydney on a clear day, the photo was taken in May 2020, alas, during the COVID-19 pandemic lock down. On the upside, there is close to zero air pollution.
In this hands-on lab, you will learn how to create and debug a Python application on a Raspberry Pi with Visual Studio Code and the Remote SSH extension. The app requires the Pimoroni Enviro+ pHAT, and reads data from the PMS5003 particulate matter (PM) and BME280 sensors and streams the data to Azure IoT Central.
- Computer refers to your desktop or laptop computer running Linux, macOS, or Windows 10.
- Raspberry Pi refers to your Raspberry Pi:)
- Raspberry Pi, SD Card, and Raspberry Pi power supply
- Pimoroni Enviro+ pHAT
- PMS5003 Particulate Matter Sensor with Cable available from Pimoroni and eBay.
This lab depends on Visual Studio Code and Remote SSH development. Remote SSH development is supported on Raspberry Pis built on ARMv7 chips or better. The Raspberry Pi Zero is built on ARMv6 architecture. It can run the solution, but it does not support Remote SSH development.
This tutorial build on the Azure IoT Python SDK 2 samples.
Follow these steps:
-
Using the Raspberry Pi Imager create a bootable SD Card Operating System image. From the Raspberry Pi Imager menu select Raspbian (other), then Raspbian List. Raspberry Pi Lite is headless, there is no UI, only a command line interface accessible over the network via SSH.
-
The Raspberry Pi Imager will eject the SD Card when the OS image has been copied to the SD Card. You need to physically eject the SD Card from your computer and reinsert.
-
Configure the Raspberry Pi WiFi networking]
-
Enable SSH on the SD Card. Create an empty file named ssh on the SD Card drive named boot.
-
Remove the Raspberry Pi Bootable image from your computer and insert into your Raspberry Pi
-
Attach the Pimoroni Enviro+ pHAT and PMS5003 Particulate Matter sensor.
-
Power on your Raspberry Pi
-
Wait for a minute for the Raspberry Pi to boot the first time
-
The find and make a note of the Raspberry Pi IP Address. The easiest way is from your computer, start a command prompt or terminal window. Try the following commands.
ping raspberrypi.local
If that doesn't work, try
ping raspberrypi
For other options see these notes.
-
Now log into your Raspberry Pi with SSH.
-
From your computer, start a command prompt or terminal window.
-
Run the following command
ssh pi@Your Raspberry Pi IP Address
for example
-
You will be prompted to trust the Raspberry Pi
-
You will be prompted for the default Raspberry Pi password. The default password is raspberry.
-
-
Update your Raspberry Pi.
-
From the SSH session you just started, run the following command on the Raspberry Pi. This will update the Raspberry Pi Operating System, install two required Linux packages, and reboot the Raspberry Pi
sudo apt update && sudo apt install -y git python3-pip && sudo apt upgrade -y && sudo reboot
-
-
Wait for the Raspberry Pi to reboot. You can tell when the Raspberry Pi is ready when the green LED on the Raspberry Pi stops flickering.
From the SSH session you started in the previous step install the following required Python packages. Run the following command.
pip3 install ptvsd azure-iot-device psutil enviroplus RPi.GPIO pylint autopep8From the SSH session, run the following commands.
git clone https://github.com/pimoroni/enviroplus-python
cd enviroplus-python
sudo ./install.shClone the Environment Monitoring solution to your Raspberry Pi. From the SSH session, run the following command.
git clone https://github.com/gloveboxes/Raspberry-Pi-Python-Environment-Monitor-with-the-Pimoroni-Enviro-Air-Quality-PMS5003-Sensor.git environment-
Install the git client.
-
Clone the Environment Monitoring solution to your computer. From your computer, start a command prompt or terminal window. Change to your preferred projects directory on your computer. Make a note of the directory as you will need to refer to that directory shortly. Run:
git clone https://github.com/gloveboxes/Raspberry-Pi-Python-Environment-Monitor-with-the-Pimoroni-Enviro-Air-Quality-PMS5003-Sensor.git environment
Setting up a public/private key pair for SSH authentication is a secure and fast way to authenticate from your computer to the Raspberry Pi. This is recommended for this hands-on lab.
The SSH utility guides you through the process of setting up a secure SSH channel for Visual Studio Code and the Raspberry Pi.
You will be prompted for:
- The Raspberry Pi Network IP Address,
- The Raspberry Pi login name and password. The Raspberry Pi default login name is pi, and the default password is raspberry.
- From Windows File Explorer, open the directory you cloned the Environment Monitor solution into.
- Open the environment directory
- Open the scripts folder
- Double click the windows-setup-ssh.cmd
The SSH utility guides you through the process of setting up a secure SSH channel for Visual Studio Code and the Raspberry Pi.
You will be prompted for:
- The Raspberry Pi Network IP Address,
- The Raspberry Pi login name and password
-
Open a Terminal window
-
Copy and paste the following command, and press ENTER
curl https://raw.githubusercontent.com/gloveboxes/Raspberry-Pi-Python-Environment-Monitor-with-the-Pimoroni-Enviro-Air-Quality-PMS5003-Sensor/master/scripts/ssh-setup.sh | bash
This hands-on lab requires Visual Studio Code. Visual Studio Code is a code editor and is one of the most popular Open Source projects on GitHub. It runs on Linux, macOS, and Windows.
- Install Visual Studio Code from here.
-
Start Visual Studio Code
-
Press F1 to open the Command Palette, type ssh connect and select Remote-SSH: Connect to Host
-
Select the pylab-pi configuration
-
Check the Remote SSH has connected.
It will take a moment to connect, then the SSH Status in the bottom lefthand corner of Visual Studio Code will change to >< SSH:pylab-pi.
-
Click on the links to install the following Visual Studio Code extensions
Ensure when you are installing the Python and Docker extensions you are installing into SSH. The following is an example of adding the Python extension into the SSH session.
Easily connect, monitor and manage your Internet of Things (IoT) assets at scale. Azure IoT Central is a hosted, extensible software as a service (SaaS) platform that simplifies setup of your IoT solution and helps reduce the burden and costs of IoT management, operations and development. Provide customers superior products and service while expanding your business possibilities.
We are going to create an Azure IoT Central application, then a device, and finally a device connection string needed for the application that will run in the Docker container.
-
Open the Azure IoT Central in a new browser tab, then click Getting started.
-
Next, you will need to sign with your Microsoft Personal, or Work, or School account. If you do not have a Microsoft account, then you can create one for free using the Create one! link.
-
Create a new Azure IoT Central application, select New Application. This takes you to the Create Application page.
-
Select Build as app
-
Select Custom app
Specify Application name, URL, enable 7 day free trial, and complete the registration form. Then click Create.
-
Add new Device Template
Click Device templates
-
Select IoT device template type
-
Create an IoT Device Template
- Select IoT device,
- Click Next:Customise,
- Click Next: Review,
- Click Create.
- Name your template Air Quality Monitor, and press Enter
-
Add an Interface
- Click Import capability model
- Navigate to the folder you cloned the solution into.
- Select Air Quality Monitor.json and open
-
Create a view
SCOPE_ID={IoT Central ID Scope}
DEVICE_ID={your device id}
DEVICE_KEY={your device key}
Tutorial: Create and connect a client application to your Azure IoT Central application (Python)
























