Sorry, you need to enable JavaScript to visit this website.

You are here

SMS alerts for hazardous air quality during bushfire season

BY Tim McMahon 02 June 2021

I woke up one morning in January 2020 and discovered that the air quality in Melbourne had dropped to hazardous levels from bushfire smoke. This hazardous air quality was extremely concerning to my wife and I with our newborn.

I wanted to receive an SMS message whenever PM2.5 levels exceeded 300 so that we could be more alert and take action (wear a mask, try to filter the air). But I didn't have any air quality sensors at home.

 

Air quality data from the EPA AirWatch API

While looking at the air quality page for a nearby suburb on the EPA Victoria website, I noticed "Connect to our developer portal". I signed up and soon discovered that the EPA have an AirWatch API. Awesome!

 

There were three things that I needed to do to get air quality info for a nearby suburb:

  1. Sign up and get an API Key via the EPA Developer Portal
  2. Read the AirWatch API documentation and figure out what the Site ID is for a nearby suburb.
  3. Create a script to call the AirWatch API and get air quality information for a particular site.

 

SMS alert via Telstra Messaging API

Now I don't want to visit the EPA website every day to see the current reading in my area, and other channels like email could easily be missed. So for this critical alert I wanted to go with SMS.

For the past few years I've been sending SMS messages using the free tier of the Telstra Messaging API for random projects like this. Your first 100 messages are free! 

You can sign up for free on https://dev.telstra.com/ and follow the API documentation to get started.

 

I found the documentation and error messages pretty helpful for getting my home projects set up quickly and easily.

Remember that when you are using the free trial to test your project, you need to register your own mobile as a "B Number" first, as the free trial version allows you to send SMS to max 5 other numbers. I used the Postman collection to do that as a once-off. 

 

Air Quality Alert

Okay, so with access to the EPA AirWatch API and the Telstra Messaging API I had:

  • Air quality data
  • A way to send SMS messages

Now I needed to set up an automated script to pull the Air Quality data every hour, and compare that to the 300µg/m³ threshold I'd set.

I whipped up a script with bash, curl and scheduled it to run via crontab on my Linux server. But after this initial kneejerk reaction to hazardous air quality, I decided to rewrite the script in Python.

 

The threshold can be configured in check_air_quality.config.json. I initially used a low threshold of around 50 while testing but I was getting too many SMS alerts so I raised it to 100. 100 isn't great, but it's pretty alarming when PM2.5 exceeds 300. I'd suggest using a threshold that you're comfortable with.

 

I scheduled the script to run on my Linux server every hour at 20 minutes past the hour using a cron job entry:

crontab -e
20 * * * * /home/user/air_quality_alert/check_air_quality.py >> /home/user/air_quality_alert/check_air_quality.log 2>&1

 

The script is up on my GitHub with detailed instructions, feel free to fork it and adapt it for yourself!

https://github.com/TimMcMahon/air_quality_alert

 

So now when the EPA AirWatch registers PM2.5 levels exceeding 300µg/m³  I'll be the first to know! Finger crossed we won't see this message this year, but better to be safe than sorry.

This is what the script does in a nutshell:

 

Here's what the SMS alerts looks like coming from my Telstra Virtual Mobile Number (with some test data):

sms alert for air quality in box hill

As you can see, air quality was shifting between Very Poor and Hazardous around the middle of January 2020.

 

 

Python all the things!

It's amazing to see Python being embraced at school by organisation like Code Club Australia and now calculators are supporting this language!

 

(my daughter Evelyn and I are already tinkering with air purifiers!)

playing with air purifier

I learnt how to code with TI-BASIC on a TI-83 Plus graphing calculator in High School. It came with a thick reference manual. My maths teacher gave me a Borland BASIC book to nurture my curiosity and encourage me to port programs from one BASIC language to another. 

 

With more and more APIs being made accessible, people can start whipping up solutions quickly in Python to satisfy their needs. Python seems to be a modern day Swiss Army Knife of coding!

 

What next?

My next project will involve using a cheap PMS7003 air quality sensor to get our own local air quality measurements at home.

 

If you have questions about this project, specifically for integrating with the Telstra Messaging API, please post on their support forum: https://dev.telstra.com/forums/messaging-api-forum

Related Blogs

's picture

By Alan Quayle

18/5/21

  • iot
  • API

Unlocking the Internet of Things with Telco APIs: Telstra’s...

As Australia’s longest serving telco, Telstra is expanding their developer program to provide...
's picture

By Sri Amirthalingam

31/3/21

  • iot
  • regional

Your regional mobile coverage questions answered

When developing an IoT solution for your business, coverage and access to a reliable network is crit...
iot home garden project with arduino and azure
's picture

By keith coutlemanis

10/11/20

  • arduino
  • azure

Azure Internet of Things Garden Project with Arduino

I want to showcase a project I have been working on to reflect the interesting things you can do wit...
's picture

By Trent Steenholdt

10/11/20

  • iot
  • DIY

Home IoT Project using Azure

In this blog series, I’m going to write about how Internet of Things (IoT) enabled my gate,...
's picture

By DIYODE Magazine

9/11/20

  • arduino
  • iot

Hands On: Long Range IoT Arduino MKR NB 1500 over the...

We put the Arduino MKR NB 1500 to the test using the Telstra network and show you how to g...
's picture

By Michelle Howie

20/10/20

  • hackathon
  • iot

Data Driven IoT Insights for sustainable communities:...

In the second TelstraDev challenge for GovHack 2020 (part 1 on Communication APIs here), we asked:...
's picture

By Michelle Howie

20/10/20

  • hackathon
  • messagingAPI

Connecting our community in an emergency with mobile...

What do you get when you give 700 Hackers, Hustlers and Hipsters across Australia and New Zealand, a...
's picture

By Michelle Howie

1/9/20

  • iot
  • developer

Wireless Application Developers Guidelines for IoT

Are you developing with the cellular IoT network? There's loads of benefits like reducing payloa...
's picture

By Michelle Howie

26/8/20

  • iot
  • captis

Capture more insights with Captis Data Loggers!

Calling all IoT makers and innovators, there’s a new device on our IoT Marketplace! It...
's picture

By Tiana Fong

18/8/20

  • iot
  • platform

Telstra's IoT Platform

The Internet of Things (IoT) is a network of physical objects which collects data from the environme...
's picture

By Michelle Howie

3/8/20

  • messagingAPI
  • Tutorials

Get Started with the TelstraDev Messaging API

Have you ever wondered what an API is and why you should care? Have you ever had a mid-career cri...
's picture

By Brendan Myers

8/4/19

  • arduino
  • mkr

Introducing the Arduino MKR NB1500

Last year we were proud to announce our partnership with Arduino to help create an (read more about...