Raspberry Pi Weather Station

Well it’s been a little over two week and the Raspberry Pi 3 Model B weather station has held up; figured now would be a good time to go a little deeper into the setup.

Telegraf has been solid in ingesting my JSON documents periodically, lets have a look at it’s SensorTag configuration:

# cat /etc/telegraf/telegraf.d/sensor_tag.conf
 command = "cat /sensor_tag.json"
 data_format = "json"
 name_suffix = "_sensor_tag"
 interval = "60s"

This telegraf configuration inserts the output of /sensor_tag.json every 60 seconds into InfluxDB.

In order to keep the JSON document up to date I have cron executing a python script every 60 seconds:

# crontab -l | grep sensor
* * * * * /root/sensor_tag.py A0:??:??:??:??:??

sensor_tag.py is a slightly modified version of my SensorTag code on Github.

Grafana 5.x Running on Raspberry Pi

Got around to upgrading my Raspberry Pi 3 Model B weather station with a newer version of Grafana, the Debian packages for ARM are hosted on Grafana’s download page under ARMv7.

Moving from a 2.x word to a 5.x has been impressive, most notably the drag, drop, and resize functionality.

I’m still using InfluxDB and Telegraf to store and populate my time data points.

Latest Raspbian’s (stretch) comes with Influx 1.0.2 and works nicely:

# dpkg -l | grep influxdb
ii  influxdb     1.0.2+dfsg1-1 armhf

While I needed to grab the Telegraf as a Linux Binary (ARM) from Influx’s download page.


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 = 'http://api.openweathermap.org/data/2.5/weather'
  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