ThingSpeak

We are using ThingSpeak to store the air quality data from all of our sensors.

ThingSpeak is ...

"... an IoT analytics platform service that allows you to aggregate, visualize, and analyze live data streams in the cloud. You can send data to ThingSpeak from your devices, create instant visualization of live data, and send alerts."

We will be creating a ThingSpeak account, a "Channel" to store your sensor data, and MATlab Analysis apps (scripts) to:

  1. send the sensor data to AirTable.com ; uses a "React" app to run the script every time new sensor data is received

  2. send email to you when the air quality is poor; uses a "TimeControl" to check the air quality every hour and send email if the air quality is poor.

There are a lot of steps to complete, but it's not difficult. Just be sure to complete each one and carefully follow the instructions.

Create your ThingSpeak account

  1. https://thingspeak.com/

  2. Click the "Sign In" icon on the upper right of the page.

  3. Click on the "Create One" link before the email entry box:
    "No account? Create One"

  4. Enter your email address, and First Name, Last Name
    (Note that this email address will receive air quality alert messages from your sensor.)

  5. Enter a password and be sure to remember it!

  6. Check your email for "Verify Email Address" from mathworks.com
    and click on the "Verify Email" link in the email message.
    Follow the instructions to complete creating your MathWorks account.
    Answer the "ThingSpeak Usage Intent" form with:
    "Personal, non-commercial projects"
    (Note that ThingSpeak is part of MathWorks.)

  7. Once again, go to https://thingspeak.com and you should see:
    "Sign-up successful"

Create your ThingSpeak channel

  1. https://thingspeak.com/channels

  2. Click "New Channel" and enter the settings for your channel:

    • Name: Air Quality

    • Description: Your name ( or anything your want - this will be visible to others)

    • Click the checkbox to the right of field 1 and field 2.

    • Enter the field names with these (you can copy/paste to avoid any errors)

      • File 1: MacAddr

      • Field 2: AirQuality

    • Click the checkbox next to "Show Channel Location"

    • Enter the latitude and longitude of your sensor's location.
      You can use
      Google Maps to find these coordinates. Enter the full street address in the search bar, right click on the marker that appears in the map to display the latitude, longitude.

      • Enter the latitude and longitude in the settings.

  3. Click "Save Channel"

Set the ThingSpeak Channel Sharing setting

  1. Click the "Sharing" tab.

  2. Click "Share channel view with everyone."

Select your ThingSpeak Channel

  1. https://thingspeak.com/channels

  2. Click on "Channels ... My Channels"

  3. Click on the "Air Quality" channel you created

Create your ThingSpeak "MATLAB Analysis" script #1

ThingSpeakMATlab_SendDataToAirTable

  1. Click on "Apps ... MATLAB Analysis"

  2. Click "New"

  3. Select "Custom (no starter code)

  4. Click "Create"

  5. In the name box, enter (copy/paste):
    SendDataToAirTable

  6. Click SendDataToAirTabl.txt and copy the entire text.
    The first line should be something like:
    % Send data to AirTable (http://airtable.com)
    Paste the entire text into the "MATLAB Code" box.

  7. Copy your Channel ID. It is displayed on the right side of the "MATLAB Code" box.
    In the MATLAB Code, replace the XXXXXXX text with your Charnnel ID:% CHANGE THIS TO YOUR THINGSPEAK CHANNEL ID!
    channelID = XXXXXXX;

  8. Scroll down to the end of the MATLAB Code box and be sure that the last line is "end."
    If not, delete any extra text that might have been picked up during the copy/paste process.

  9. Scroll down and click "Save."

Create your ThingSpeak "MATLAB Analysis" script #2

Air_Quality_Alert_Email

  1. Click on "Apps ... MATLAB Analysis"

  2. Click "New"

  3. Select "Custom (no starter code)

  4. Click "Create"

  5. In the name box, enter (copy/paste):
    Air_Quality_Alert_Email

  6. Click Air_Quality_Alert_Email.txt and copy the entire text.
    The first line should be something like:
    % Send data to AirTable (http://airtable.com)
    Paste the entire text into the "MATLAB Code" box.

  7. Copy your Channel ID. It is displayed on the right side of the "MATLAB Code" box.
    In the MATLAB Code, replace the XXXXXXX text with your Charnnel ID:
    %
    CHANGE THIS TO YOUR THINGSPEAK CHANNEL ID!
    channelID = XXXXXXX;

  8. Scroll down to the end of the MATLAB Code box and be sure that the last line is "end."
    If not, delete any extra text that might have been picked up during the copy/paste process.

  9. Scroll down and click "Save."

Create the "Alerts API Key" and change your timezone

  1. Access your ThingSpeak "My Profile" by clicking on the round button on the upper right that probably contains your initials. Click on "My Profile."

  2. Under "Username", click "Edit" and change the time zone as appropriate for your location.

  3. Click "Update Profile"

  4. Click the button to the right of "Alerts API Key" to create a new key.

  5. Copy the "Alerts API Key"

Add the "Alerts API Key" to script #2

  1. Click on "Apps ... MATLAB Analysis"

  2. Click on "Air_Quality_Alert_Email"

  3. Locate the line that says:
    % CHANGE THIS TO YOUR ThingSpeak API Key!
    alertApiKey = 'XXXXXXXXXXXXXXXXXXX';

  4. Replace XXXXXXXXXXXXXXXXXXX with the "Alerts API Key" you copied in the previous step.

  5. Scroll down and click "Save"

Create a React App to Send Data to Air Table

  1. Click on "Apps ... React"

  2. Click "New React"

  3. Enter the required configuration"

    • React Name: SendDataToAirTable

    • Condition Type: Numeric

    • Test Frequency: On Data Insertion

    • Condition:

      • If channel: <your ChannelID>

      • field: AirQuality

      • is greater than 0

    • Action: MATLab Analysis
      Code to execute: SendDataToAirTable

    • Options: Run action each time condition is met

  4. Click "Save React"

Create a TimeControl App to Send Email Alerts

  1. Click on "Apps ... TimeControl"

  2. Click "New Time Control"

  3. Enter the required configuration"

    • Name: Air_Quality_Alert_Email

    • Frequency: Recurring

    • Recurrence: Hour

    • Every: 1 (hour)

    • Action: MATLab Analysis
      Code to execute: Air_Quality_Alert_Email

  4. Click "Save TimeControl"