SensorTag data merged with Open Weather Maps

About a week ago I worked on SensorTag metrics with Grafana.

This week had some interesting weather today here in Austin, and I wanted to see to visualize it as well. Luckily Open Weather Maps offers a free API for gather near real-time weather data based on city code.



def __get_open_weather_data():

  url_path = ''
  api_key = '??????????'
  url = '%s?zip=73301&APPID=%s'

  res = requests.get(url % (url_path, api_key))
  if res:
    if res.json().get('main'):
      return res.json()

  res = requests.get(url % (url_path, api_key))
  if res:
    if res.json().get('main'):
      return res.json()

def get_open_weather():

  data = __get_open_weather_data()

  # format our json response
  temp = round(data['main']['temp'] * 9/5 - 459.67, 2)
  pressure = round(data['main']['pressure'], 1)
  humidity = round(data['main']['humidity'], 2)
  rain = round(data['rain'].get('1h', 0.00), 2)
  clouds = data['clouds']['all']
  wind = data['wind']['speed']

  return dict(

Then I merge with my SensorTag data, appending these new keys to my json file:

$ cat /sensor.json
 "open_weather_temperature": 71.65,
 "temperature": 74.19,
 "open_weather_pressure": 1018.5,
 "light": 0,
 "humidity": 55.16,
 "pressure": 989.8,
 "open_weather_humidity": 99,
 "open_weather_rain": 7.07,
 "open_weather_clouds": 48,
 "open_weather_wind": 2.81

SensorTag metrics with Grafana

If you haven’t been following, I’ve done a little research into the Texas Instruments SensorTag starting with post RaspberryPi 3 and SensorTag.

Just the other day I stumbled upon the official Texas Instruments wiki for the SensorTag CC2650, the wiki does a good job outlining the formulas to calculate each sensors value.

This lead me to write a minimal Python class (see on Github) using some of the formulas found in the wiki. Beyond just the Python classes, I wrote in a periodic process; this process will save the sensor data to screen, and write to /root/sensor.json every five seconds.

pi@raspberrypi:~# cat /sensor.json
 "pressure": 987.2,
 "humidity": 58.44,
 "temperature": 75.65,
 "light": 19.43

To better visualize the gathered data I decided to store all metrics in Telegraf, all I needed was a simple execution plugin:

pi@raspberrypi:~# cat /etc/telegraf/telegraf.d/sensor_tag.conf
 command = "cat /sensor.json"
 data_format = "json"
 name_suffix = "_sensor_tag"
 interval = "5s"

Then on my workstation I installed Grafana, and connected Telegraf as a remote data source.

This is the type of data I’ve been gathering and storing from the SensorTag, seems like we could make a weather station pretty easy.