Raspberry Pi as a Weather Underground Personal Weather Station

Background

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.

PWS Screenshot

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.

Overview

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.

Raspberry Pi + Breadboard

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.

DH22 Outside

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:

$nano pi_wunderground.py

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 screen
$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:
$screen -r

For a future post…

  • How to run the script as a service that starts automatically with your Pi
  • How to add additional sensors

Questions? Comments?

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.

  • Pingback: Raspberry Pi as a Weather Underground Personal Weather Station #piday #raspberrypi @Raspberry_Pi « adafruit industries blog

  • Tim Müller-Seydlitz

    Thanks for the tip. I was not aware of weather underground. So far I am experimenting with cosm and sen.se to upload my data. Both didn’t convince me entirely.
    Can you adjust the link to the weather underground wiki?

  • Tobin Greensweig

    Link is fixed, thanks for the good catch! I haven’t experimented with either of those sites, but Weather Underground is cool because it’s just weather and integrates with other peoples data on the “weather map.”

  • Tobin Greensweig

    Just updated my python script with some error checking for socket errors etc. It’s on github.

  • Christopher Somerlot

    I found that running a similar script for uploading to cosm every 5 minutes was better achieved as a cron job rather than a service.

  • Tobin Greensweig

    That’s a very interesting idea, aside from being easier to setup a cron job was there another reason you found it worked better?

  • Paul Norton

    I too am using my Raspberry Pi to interface with my Rainwise Mk III weather station and update Weather Underground:

    http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KCASANTE1

  • http://www.gigabyte2.it Gigabyte2

    It doesn’t work for me :( It gives to me this message: “Upload not successful, check username, password, and formating.. “

  • http://www.gigabyte2.it Gigabyte2

    Ok, I fix the problem

  • Szergely

    Hello Tobin! I’ll try it now and says me “Upload not successful, check username, password, and formating.. ” The sensor is works fine. :/

    ./Adafruit_DHT 2302 2

    Using pin #2

    Data (40): 0×2 0x1e 0×0 0xdb 0xfb

    Temp = 21.9 *C, Hum = 54.2 %

  • Szergely

    Hello! How to fix that?

  • http://www.dondersteen-sieraden.nl Paul van der Wal

    I’ve got the same error…
    every time again

    But when in put the string together in a browser;
    copy paste and with some fake data;

    http://rtupdate.wunderground.com/weatherstation/updateweatherstation.php?ID=IGRONING65&PASSWORD=XXXXXX&dateutc=2014-03-10%2015:02:38.821569&tempf=70&humidity=38&softwaretype=RaspberryPi&action=updateraw&realtime=1&rtfreq=2.5

    with the correct password offcourse ;)
    Then i DO get a succes!
    so the python programming is broken somewere…
    the output from adafruit is correct and works, uploading to Gdocs is not a problem…
    i can’t seem to fix it…