Use The Air Quality Wing Sensor to Monitor Your Air Quality With Google Docs

Jared Wolff · 2019.4.8· 9 Minute Read · particle · air quality

Main image

Air quality.

You probably think about it more now that our clean air has turned into a permanent haze across the sky.

Yuck.

I’ve previously written about the subject. This post is a straight-to-the-point version which will get you up and running quick!

Gather the Goods

The Circuit Board and Components

Get everything together that you’ll need for this project.

This includes:

  • A Particle Mesh board (Argon, Boron, Xenon). You can get them almost anywhere. Buying direct always works too. Note: if you’re just starting out, the Argon is your best bet.
  • Air Quality Wing Board.
  • Honeywell HPMA115S0 Particle Sensor.
  • Cable for HPMA115S0 Sensor. ( The last three you can get here. )

The Leg Bones Connect to The ..

Put everything together in the short few steps below:

  1. Attach the Particle to the Air Quality Wing board Attach the Particle to the Air Quality Wing

  2. Connect the HPM Particle sensor to the Air Quality Wing using the cable Connect the HPM Particle Sensor

  3. Plug in USB! Connect USB

Installing Particle Workbench

Particle Workbench is the place that all your Particle Mesh development will happen. Its technically a plugin on top of Microsoft’s Visual Studio Code. You can get it in two ways:

Download it here directly from Particle: https://www.particle.io/workbench

Or, install Visual Code directly: https://code.visualstudio.com

Then you can install the Particle Workbench application using the extensions window in Visual Code.

Visual Code install Particle Workbench

Click the green Install next to Workbench and all the dependencies will be installed!

Setting Up and Using Git

Throughout this guide, we’ll be using Git extensively to download example code. You’ll have to install it on your computer if you haven’t already. Here’s a link to the download page.

Before we can run any commands, git has a dependency on ssh. In order to use services like Github, Gitlab and Bitbucket, you’ll have to register your SSH public key. For Unix devices your private key is located in ~/.ssh. By default it’s called something like id_rsa.pub.

If you’re missing it, you can create one using ssh-keygen:

jared@ceznamac:~/.ssh$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/jaredwolff/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/jaredwolff/.ssh/id_rsa.
Your public key has been saved in /Users/jaredwolff/.ssh/id_rsa.pub.

You’ll want to copy the contents of id_rsa.pub and add it to your Git server of choice.

Here’s a screenshot from Github’s settings page. There are several keys set up for this account.

SSH Key setup in Github

Click the green New SSH Key and copy the contents of your id_rsa.pub (the .pub is important!) to the Key text field:

Add new SSH key in Github

Once you’ve added your key, you can check by running the following command:

ssh -T git@github.com

If you are prompted to add the RSA fingerprint, select yes.

jaredwolff:~ jaredwolff$ ssh -T git@github.com
The authenticity of host 'github.com (140.82.114.3)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.

Afterwards you should get some output:

Hi jaredwolff! You've successfully authenticated, but GitHub does not provide shell access.

If you got this far, that means you’re set up! If you’re having issues, backtrack to make sure you’ve setup your SSH key appropriately. Github also has some great in-depth support on the subject.

Installing the Command Line Interface

One thing you’ll have to do separately from installing Particle Workbench, is to install the CLI. For Mac and Linux, the easiest thing to do is run this command:

bash <( curl -sL https://particle.io/install-cli )

This will install everything you need to get started with developing on Particle Mesh.

For Windows, you can go here to download the installer.

As you become more familiar with the Particle ecosystem, you’ll find yourself using the CLI more and more. Time to start using it now!

Provision your Particle Device

The easiest way to provision a Particle Device, especially if you’re new, is to use your smart phone.

Here’s an example using an Argon.

  1. Plug in the USB cable and hold the mode button at the same time. Continue holding the mode button until the RGB LED starts blinking blue. As long as you have the original Tinker firmware installed, the device should always behave this way.

    If your device has never been provisioned before, it will start up in this mode. Skip this step.

    Argon ready to roll

    Note: make sure you attach your Wifi antenna. It should plug in on the left side. (Above the A in Argon)

  2. Install the Particle App if you haven’t already.

  3. Open the Particle App on your phone.

    Particle Mesh Setup App

  4. Log in by tapping Get Started if you haven’t already.

    Sign into Particle

  5. Enter your Authenticator code if you set up with 2FA. (Highly recommended)

    Enter Auth Code

  6. Tap the plus button in the top right Then tap Argon/Boron/Xenon.

    Add new Argon/Boron/Xenon

  7. The app then should walk you through the remainder of the process

    Scan data matrix step

  8. During the setup process, the app will ask you to name this device. Keep this name handy for the next step in the process.

  9. Also, if you have set up a mesh network, make sure you remember the Admin password for your mesh network.

Download the Code

The Air Quality Wing does require a Particle Argon, Boron or Xenon to work. You will also need to program the firmware. Here are the steps to get everything up and running.

First, let’s clone the code from your freshly set up Github account.

git clone git@github.com:jaredwolff/particle-squared-code.git

This will create a folder with all the firmware source files.

Next let’s open up that folder using Particle Workbench.

Workbench with ino file

Our main source file particle-squared.ino can be found src directory. Double click to open it up.

At the bottom of the screen select your device type. You should select argon boron or xenon depending on what board you have.

Find the .ino file

Select your firmware version. As of this writing it’s recommended to use 1.4.0.

Choose device type

Remember what I said earlier about saving the name of the device? Now’s the time to use it! Enter it in the box next to the Device OS version.

Chose Device OS version

Flash your device

Now, let’s flash the firmware! We’ll be using Particle’s Cloud Flash capabilities.

The easiest way to invoke a Cloud Flash is by clicking the lightning bolt button in the top right of Particle Workbench

Chose device name

During programming you should see your device flash purple. It may take up to several minutes especially if the OS needs to be upgraded.

Check your data

As a final sanity check, let’s make sure that the data is being published to the cloud.

First let’s check locally using the serial console.

Make sure your device is connected and then run:

particle serial monitor --follow

Starting particle serial monitor

If you wait long enough you should see updates on your command line:

Last login: Sun Sep 15 16:01:32 on ttys004
pjaredwolff:~ jaredwolff$ particle serial monitor
Opening serial monitor for com port: "/dev/tty.usbmodem145201"
Serial monitor opened successfully:
ccs811 ver 2.0.1
ccs811 no update nerestore sgp30 baseline
Air Quality Wing
temp rdy
tvoc rdy
sgp30 rdy
bme680 rdy
data send
temp rdy
tvoc rdy
sgp30 rdy
bme680 rdy
data send

Once we see it locally, let’s check the Particle Cloud.

Login and navigate to your newly provisioned mesh device.

Navigate to device in Particle Console

Then you can watch the console for updates:

See data. Modify set_period if necessary

Updates not happening fast enough? You can update the measurement period by changing set_period to 30000. Once you see data you can set it back to the default of 120000 or simply reset the device.

Sending Data to Google Docs

A easy way to visualize your data is to use Google Docs to visualize your data. Here are the steps:

  1. Create a new Google Sheet
  2. Then click the Tools menu and click Script Editor Script editor
  3. Create a new script
  4. Insert the below code into the script:

    //this is a function that fires when the webapp receives a POST request
    function doPost(e) {
    
     //Return if null
     if( e == undefined ) {
       Logger.log(“no data”);
       return HtmlService.createHtmlOutput(“need data”);
     }
    
     //Parse the JSON data
     var event = JSON.parse(e.postData.contents);
     var data = JSON.parse(event.data);
    
     //Get the last row without data
     var sheet = SpreadsheetApp.getActiveSheet();
     var lastRow = Math.max(sheet.getLastRow(),1);
     sheet.insertRowAfter(lastRow);
    
     //Get current timestamp
     var timestamp = new Date();
    
     //Insert the data into the sheet
     sheet.getRange(lastRow + 1, 1).setValue(event.published_at);
     sheet.getRange(lastRow + 1, 2).setValue(data.temperature);
     sheet.getRange(lastRow + 1, 3).setValue(data.humidity);
     sheet.getRange(lastRow + 1, 4).setValue(data.pm10);
     sheet.getRange(lastRow + 1, 5).setValue(data.pm25);
     sheet.getRange(lastRow + 1, 6).setValue(data.tvoc);
     sheet.getRange(lastRow + 1, 7).setValue(data.c02);
    
     SpreadsheetApp.flush();
     return HtmlService.createHtmlOutput(“post request received”);
    }

Configure Webhook

Google Docs Webhook

  1. Go to Publish and click Deploy as Web App
  2. Set Execute the app as yourself
  3. Then set Who has access to the app to Anyone, even anonymous. (Important: if you’re working with. mission critical data, you may want a more robust and custom solution. This allows anyone, if they have your web hook link to post data to that page!)
  4. Change the Project Version to new and deploy!
  5. Copy the Current App URL that the output provides.

Configure Particle Cloud

Configure Particle Cloud

  1. In the Particle.io console, go to the Integrations section and Create a New Webhook
  2. Fill in the name of the event that get’s forwarded from the code (in this case it’s blob)
  3. Enter the Current App URL from the last step in the URL Box
  4. Set the request type to POST
  5. Set the request format to JSON
  6. Target the device you’ll be using (or leave it as is if you only have one device)
  7. Click save

Beam me up

Particle Visual Code

It’s time to program your board. Follow the steps below:

  1. Setup your Particle Account and Particle Mesh device. Use the Quickstart if you haven’t done this before.
  2. Download Particle Workbench and install if you haven’t already. Instructions here.
  3. Get the code here.
  4. Once the code is downloaded, open it with Visual Code (that you installed in Step 1)
  5. Login to Particle if you haven’t already (The fastest way is to hit Command + Shift + P to open the command window. Then start typing login)
  6. Publish to Particle Cloud - Again this uses the command window. Use the same Command + Shift + P as above and type Cloud Flash.
  7. Once you’ve found the Cloud Flash option, press enter.
  8. Your board should be programmed shortly. You can watch the LEDs for changes during this time. Once it’s glowing blue, you’re good to go!

Last Step (I promise)

  1. In the Google sheet you can create a header in the first row with all the labels. Google Sheets View
  2. You should notice by now that new data is showing up in the sheet (if you set everything up correctly). Go back to the previous steps if you don’t see it.
  3. You can graph the data by selecting a full column and creating a new chart from it. Graphs in Google Sheets
  4. You can graph everything in one or in separate like I’ve done above. Here’s an example from my setup.

If everything is working and you have some pretty graphs, congrats!! If you’re ready to move on to the next step using an IoT service like Adafruit’s check out my full guide here.

The Ultimate Guide to Particle Mesh Cover

Get Ready for the Ultimate Guide

Signup to get updates on The Ultimate Guide to Particle Mesh. Early subscribers get a discount when it becomes available!

Sign me up!

You may also like

How-to Event Handling on Particle Mesh

Deploying devices using Particle’s Cloud is easy. Publishing to the cloud is dead easy. Finding a reliable way to do the opposite can be.. complicated. This is especially true for…

Particle Mesh App Highlights

The Particle application for iPhone and Android can be a handy tool. Particle has been working hard on improvements to make it more versatile than it used to be. No longer are the…

How to Real Time Processing on Particle Mesh

Sometimes you run into an application that requires something to happen in real-time. I’m not talking about seconds or milliseconds, we’re talking about microsecond accuracy here.…