I live in an area where there isn’t a lot of easily accessible or good quality weather information. A lot of the websites that claim to provide local weather are actually funneling readings from the closest international airport which is 100km away which is not representative.
Weather Underground is a website that integrates all the standard weather sources (airports, governments, etc) with a network of more than 35,000 personal weather stations on a website providing rich weather information. It’s a great website for anyone to quickly check the website, but especially good for hobbyists, pilots, or anyone interested in weather. The company has an interesting history worth reading.
A Personal Weather Station (PWS) is basically equipment setup by an individual to measure the outdoor temperature, humidity, wind speed/direction, barometric pressure, etc. Weather Underground allows for individuals to log the data from their stations on their servers so it’s available to the world and fully integrated into the “weather map.” Lots of companies make off the shelf hardware and software for this, but since the protocols for this aren’t difficult, I thought it would be fun to make an inexpensive station using the Raspberry Pi! The best information about Wunderground PWS’ is on the Wunderground Wiki.
For my weather station, I decided to start with just temperature & relative humidity. In the future I might decide to barometric pressure and wind speed. I based the the project off of the Adafruit DHT Humidity Sensing on Raspberry Pi with GDocs Logging tutorial which I’ll refer to a lot in this blog post. This project is very similar, but instead of uploading the data to a google docs spreadsheet we send it off to Wunderground.
Setup a PWS on the underground website
Before sending any data to Wunderground, you must first sign up for a free Weather Underground account and add then a a new personal weather station to it. Adding a new station basically means telling Wunderground exactly where (geographically) the data they will be receiving is coming from. Once you’ve signed up, here is the direct link to add a new station. Make a note of the station ID of your newly created station.
Connecting the Temp/Humidity sensor to the Pi
I opted for the wired version of the DHT22 temperature/humidity sensor. Wiring it up to the Pi isn’t difficult and requires no extra components (aside from a breadboard or some header connectors). In this photo, the sensor is connected via the terminal block on the right which goes through the breadboard to the cobbler and eventually to the Pi GPIO Port 4.
I extended the cable of my sensor 2 meters so I could place the sensor outside (consult this page for optimal sensor placement). Although not weatherproof, I liked the housing and that everything was all contained together. At some point I’ll put it into a solar radiation shield to improve accuracy and keep it safe from the elements.
The Adafruit post provides a c based driver for polling the sensor for data. Download and get it setup per these instructions. Make sure you can run it from the shell prompt and see reasonable data before continuing.
Uploading the data to Wunderground
Now that you have your sensor connected and functioning, the next step is to upload this data to weather underground. I’ve created a basic script to which reads the sensor using the Adafruit driver, then uploads to Wunderground using an HTTP GET request. A complete explanation of formatting for this request is available on the here on the Wunderground Wiki. You can view the script here or clone my script from github using this command:
$git clone https://github.com/tgreensweig/Raspberry_Pi_wunderground.git
Next, you need to configure the script so it knows which DHT sensor you are using, the time delay between uploads, and your personal weather station account information. Edit the script with and set:
In order to run, the Adafruit_DHT file (c program that queries the sensor) must be located in the same directory so you’ll need to execute something like:
$cp /path/to/the/adafruit/script/Adafruit_DHT /path/to/the/pi_wonderground/Adafruit_DHT
Now just run it! You’ll need to do it as root due to the Adafruit_DHT so use:
$ sudo python wunderground.py
2013-03-02 09:28:56.141678 - Successful Upload
Temp: 68.9 F, Humidity: 42.1 %
Next upload in 600 seconds
You can now sign into your Wunderground personal weather station and view the posted data. The URL of mine is: http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IHADAROM2
Running the Wunderground uploader script in the background
For the data to keep updating online the script must be running on your Pi which can be a bit annoying if you want use your Pi for other things. The best option would be to run the script as as service which automatically started with the Pi and I’ll cover how to do this in another post. A workaround, however, is to use the linux
screen command. This command allows you to run multiple sessions that persist even after logging off. I’ll explain the basics below but a more complete explanation for using screen is available on this tutorial.
#First install screen with:
$sudo apt-get install screen
#run the Wunderground uploader script and wait to see the first measurement
$sudo python pi_wunderground.py
2013-03-02 11:31:21.593304 - Successful Upload
Temp: 71.8 F, Humidity: 35.5 %
Next upload in 600 seconds
#type control-a then push d, this will bring you back to your original terminal
#you can return to the terminal running the script by typing:
For a future post…
- How to run the script as a service that starts automatically with your Pi
- How to add additional sensors
Since I may have glossed over some of the basics, let me know if you have any questions or run into any trouble while running through these steps.