Purple Air and AwAir Sensor data in Grafana

Foreward

This is just a little helper on how to get Purple Air and AwAir JSON data into Grafana. It’s pretty straightforward and of course that means it took me a couple days of tinkering to figure it out. The way telegraf parses the Purple Air JSON data needs to be modified as it pulls some of the numerical values in as strings and not integers or floats. I needed to use telegraf’s processor converter as well to translate those strings into a format InfluxDB/Grafana liked.

Pre-requisites

  • This article assumes you have a basic understanding of a “TIG” stack (Telegraf, InfluxDB, Grafana) that’s all configured and working
  • For AwAir only – A local (network accessible) AwAir sensor
  • For Purple Air – A local sensor provides much more data, pulling data from PA’s website also works, just click a sensor on the map and use the JSON addresses it provides. Some of the converter stuff might get a little tricky but it will work
  • I used 2 telegraf plugins to get the data: Converter Processor & HTTP JSON

Getting Purple Air data into Grafana

  1. Go-to http://yourpurpleairsensorip/json and verify you get back a bunch of JSON data.
  2. On your TIG stack, navigate to your telegraf installation dir and edit the config file.
    1. Normally in Linux /etc/telegraf/telegraf.conf
  3. Add the below snippet of code to your telegraf.conf file (change the server IP’s in the code):
[[inputs.httpjson]]
  name = "PurpleAirLocal"
  servers = [
    "http://purpleairsensorIP/json",
    "http://purpleairsensorIP2/json",
  ]
  response_timeout = "10s"
  method = "GET"
  1. Modify and add the below code to the telegraf.conf file as well. Choose which JSON fields you want to use in Grafana and add them to float under [processors.converter.fields]
    Side note: Not all of the fields need to be converted, some come through as Integers or Floats. Below are just the ones I used and needed
[[processors.converter]]
  [processors.converter.tags]
    measurement = []
    string = []
    integer = []
    unsigned = []
    boolean = []
    float = []

  [processors.converter.fields]
    measurement = []
    tag = []
    string = []
    float = ["pm1_0_cf_1","pm2_5_atm","pm2_5_cf_1","p_2_5_um"]
    unsigned = []
    boolean = []
  1. Restart telegraf and the data should now be going into your InfluxDB and be usable in Grafana.
  2. Create your query in Grafana utilizing your new data source!
Here is my query
And the result

Getting AwAir data into Grafana

Similar to the above only there is no need to convert some fields to floats.

  1. In your AwAir mobile app, enable local sensor
  2. Go-to http://yourAwAirsensorip and verify you see the data page
  3. On your TIG stack, navigate to your telegraf installation dir and edit the config file.
    1. Normally in Linux /etc/telegraf/telegraf.conf
  4. Add the below snippit of code to your telegraf.conf file (change the server IP’s in the code):
[[inputs.httpjson]]
  name = "AwAir"
  servers = [
    "http://yourAwAirIP/air-data/latest",
  ]
  response_timeout = "10s"
  method = "GET"
  1. Restart telegraf and the data should now be going into your InfluxDB and be usable in Grafana.
  2. Create your query in Grafana utilizing your new data source!
The query I used
And the result

Leave a Reply