Raspberry Pi as a Weather Underground Personal Weather Station


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.


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

#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.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;


    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…

  • Tepames

    Hi folks I think I know what’s the problem

    I had the same error and it’s because the timestamp has a blank space just after the month. when you paste it in a web browser automatically replace that blank space with % sign

    &dateutc=2014-03-10 2015:02:38.821569

    So I made a modification in the code to fix that error

    just after the while true condition you can add this:

    currentDate=currentDate.split(” “)
    strDate=fecha[0] + “%” + fecha[1]

    with this code you split the timestamp by the blank space and you only need to concatenate those two parts in another one with the % sign

  • Jim M

    Cannot seem to get it to run. Here is the output:

    pi@raspberrypi ~ $ sudo python wunderground.py
    Traceback (most recent call last):
    File “wunderground.py”, line 27, in
    sensor_output = subprocess.check_output(["./Adafruit_DHT.py 2302 4", sensor_type, sensor_gpio]);
    File “/usr/lib/python2.7/subprocess.py”, line 537, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
    File “/usr/lib/python2.7/subprocess.py”, line 679, in __init__
    errread, errwrite)
    File “/usr/lib/python2.7/subprocess.py”, line 1259, in _execute_child
    raise child_exception
    OSError: [Errno 2] No such file or directory
    Any ideas what the problem is? Not a Linux expert here.

  • Tepames

    I’m using a similar sensor but in an Arduino UNO board and it’s conected to mi raspberry pi but check you follow all the steps in this post. Did you copy the adafruit script to the same folder of the wunderground script?

  • Jim M

    Well, I moved the whole Adafruit folder into the wunderground folder. That gives me a hint. Will check that out and do it some different ways.

  • Jim M

    Still having problems here. The Adafruit example runs and reports back temp and humidity like is should. This is what reports back when I run wunderground.py
    Traceback (most recent call last):
    File “wunderground.py”, line 27, in
    sensor_output = subprocess.check_output(["./Adafruit_DHT", sensor_type, sensor_gpio]);
    File “/usr/lib/python2.7/subprocess.py”, line 537, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
    File “/usr/lib/python2.7/subprocess.py”, line 679, in __init__
    errread, errwrite)
    File “/usr/lib/python2.7/subprocess.py”, line 1259, in _execute_child
    raise child_exception
    OSError: [Errno 2] No such file or directory

    I wonder if Adafruit has changed something that causes Tobin’s script to fail to run?