doug dobies
about | projects | linkedin | github | twitter |
Weather Graphing with DarkSky, Grafana, and InfluxDB

I'm one of those people that like data points, I like graphing weather especially. Recently I started using Grafana to create fancy graphs for various things, and weather is one of those things. There are a bunch of ways to do this, but I'm using the DarkSky API to pull weather data, then doing some simple manipulation via a shell script to parse relevant weather values, and finally I'm using curl to push those values to an InfluxDB instance.

After all of that happens, eventually I get graphs that look like this.




Below is the shell script I created to handle the heavy lifting.


#!/bin/bash
#
# Your Darksky.net API key
API="YOUR_API_CODE"

# Your geographic location
LOCATION="YOUR_LATITUDE,YOUR_LONGITUDE"

# file to save weather data to
OFILE="weather.data"

# remove any old weather.data files
rm $OFILE

wget -O $OFILE https://api.darksky.net/forecast/$API/$LOCATION 


# Get Temperature
TEMP=`cat $OFILE |grep currently |cut -d: -f14 |cut -d. -f1`

FEELSLIKE=`cat $OFILE |grep currently |cut -d: -f15 |cut -d. -f1`



# This needs extra steps, returns a percentage via . ie: 0.71 for 71%
# so we have to grab the 71 and nothing else, ie the ccond cut.
HUMIDITY=`cat $OFILE |grep currently |cut -d: -f17 |cut -d. -f2 |cut -d, -f1`

#Push all this into a local InfluxDB in a db called MyWeather

curl -XPOST 'http://your.website.com:8086/write?db=MyWeather' --data-binary 'Temperature value='"$TEMP"''

curl -XPOST 'http://your.website.com:8086/write?db=MyWeather' --data-binary 'FeelsLike value='"$FEELSLIKE"''

curl -XPOST 'http://your.website.com:8086/write?db=MyWeather' --data-binary 'Humidity value='"$HUMIDITY"''

# fi

<this is a work in progress>