Air Quality is one of those things you do not pay attention to when things are the way they should be, but you become acutely aware of when it reaches unhealthy levels, especially for those who are sensitive such as children, people with cardio-pulmonary diseases, and other respiratory ailments.
Air quality varies vastly even in a small region because pollution can build up around industries or busy areas, so it is important to monitor what is happening in your immediate proximity.
To address this issue, in this tutorial we will show you how to gather air quality data using an IoT device, store them in the cloud and showcase them in a neatly organized dashboard.
If you need help in deploying this solution or building something similar please contact Waylay.io for the low-code IoT Solution or Zalmotek.com for IoT-enabled hardware prototypes.
We have picked the M5Stack Air Quality Kit based on the PMSA003 Digital laser dust sensor for this application. The M5Stack ecosystem is based on the ESP32 SoC and is beautifully integrated with a big enough screen for a User Interface.
Install Thonny following the steps on the official website.
2
Setting up the device
Connect the M5Stack kit to your PC using the provided USB Type-C cable.
Launch M5Burner, download the UIFlow(CORE). Click the Erase button, wait for it to finish, and then press the Burn button to upload the UIFlow(CORE) firmware on the device. We have used 1.8.1_en. You will be prompted for the WiFi details that the device will use to connect to your local network. If the burn fails, change the baud rate to a lower one.
On Linux, make sure your user is part of the dialout group by running:
sudo adduser $USER dialout
The device will be programmed and you will be greeted by a series of screens showcasing the available features.
All is well. Now let's set up the cloud solution!
3
Setting up the cloud solution
Register on Waylay IO if you have not already and log in.
Go to Resources and add a resource. Name it something like AirQuality. This resource is practically your device representation in the cloud where you will send the data.
Add a new property with the customerkey and the Zalmotekvalue.
Add another property with the tagskey and the [ "AirQualityMonitor" ]value.
Go to Webscripts in the left main menu and add a new one. Name it something like AirQualityIngestion and add the following details in the body:
asyncfunctionhandleRequest (req, res) {
if (!req.body) {
// No body foundreturn
}
// Parse body if neededlet payload = req.body
if (typeof payload === 'string' || payload instanceofString)
payload = JSON.parse(payload)
/*
You can do some processing of the payload over here.
*/// Post values to our resource
waylay.data.baseUrl = 'https://data-io.waylay.io'await waylay.data.postSeries('replace_with_resource_id', payload, { store: true, forward: true })
.catch(e =>console.error(e.message))
res.sendStatus(200)
}
Be sure to replace thereplace_with_resource_id placeholder with the actual resource_id from the above step. Navigate to the resource page to get it. Ours is something like 453472c9-8553-4b12-b24f-fc6e052e8255. Press Save once you have pasted the correct details.