Installing a USB Weather Station on a Raspberry PI Part 1

One of the reasons for having multiple PI’s was to have one take over duties from an aging ITX based Linux box of reading from a USB Weather station and uploading the data to both it’s website and WeatherUnderground.

Unfortunately this project got pushed forward when, last Thursday morning, the ITX box decided to die on me. I think it’s power supply finally gave out after 9 years of service.

So this is the first part of a series on setting up a USB weather station onto a Raspberry PI.

Part 1 – The Weather Station

The weather station that I’ve been using since November 2010 is one I bought from Maplin. They usually sell for about £125 but a couple of times a year they reduce them down to between £50-£70. N96FY USB Wireless Weather Forecaster. At the time of writing this they’ve got it reduced to £69.

The external components of the Weather Station


It consists of the external sensors and an internal touch screen unit. All that’s needed is a USB A-A cable to connect the touch screen to the PI.

Configuring the Raspberry PI

First I started with a blank copy of raspian on a 4Gb SD Card. Booted the pi up and configured it to use the entire card. With raspian this is easy as you get prompted on the first boot to do it. At the same time I enabled the ssh server from that same menu.

Installing the software

Now this is based on the instructions over on dragontail.co.uk who got a Raspberry PI working with one of these weather stations. Those instructions are for the Debian based image. I’ve taken them and modified them to get working with raspian so there are a few minor changes.

First we need to install some dependencies:

pi@kell ~ $ sudo apt-get install git python-dev
pi@kell ~ $ sudo apt-get install gnuplot python-simplejson python-tweepy python-paramiko

Next we need to download and compile the latest versions of a few dependencies as the versions in the repos are not up to date.

First is Cython:

pi@kell ~ $ mkdir work
pi@kell ~ $ cd work
pi$kell ~/work $ wget http://pypi.python.org/packages/source/C/Cython/Cython-0.16.tar.gz
pi$kell ~/work $ tar xzf Cython-0.16.tar.gz
pi$kell ~/work $ cd Cython-0.16
pi$kell ~/work/Cython-0.16 $ sudo python setup.py install

That will take a while…

Next is libusb:

pi$kell ~/work/Cython-0.16 $ cd ~/work
pi$kell ~/work $ wget http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.9/libusb-1.0.9.tar.bz2
pi$kell ~/work $ tar xjf libusb-1.0.9.tar.bz2
pi$kell ~/work $ cd libusb-1.0.9
pi$kell ~/work/libusb-1.0.9 $ ./configure
pi$kell ~/work/libusb-1.0.9 $ make
pi$kell ~/work/libusb-1.0.9 $ sudo make install

Next is cython hidapi:

pi$kell ~/work/libusb-1.0.9 $ cd ~/work
pi$kell ~/work $ git clone https://github.com/gbishop/cython-hidapi.git
pi$kell ~/work $ cd cython-hidapi
pi$kell ~/work/cython-hidapi $ vi setup.py

Now we need to change the path to libusb from /usr/include/libusb-1.0 to /usr/local/include/libusb-1.0. Make that change then save.

pi$kell ~/work/cython-hidapi $ sudo python setup.py install

Now finally pywws:

pi$kell ~/work/cython-hidapi $ cd ~/work
pi$kell ~/work $ wget http://pywws.googlecode.com/files/pywws-12.05_r521.tar.gz
pi$kell ~/work $ tar xvzf pywws-12.05_r521.tar.gz
pi$kell ~/work $ cd pywws-12.05_r521
pi$kell ~/work/pywws-12.05_r521 $ sudo python TestWeatherStation.py

Thats the basic installation, for the rest I’d suggest reading the pywws documentation.

The one thing I’d suggest is moving the installation out of your home directory, for me thats:

pi$kell ~/work/pywws-12.05_r521 $ cd ~/work
pi$kell ~/work $ sudo mv pywws-12.05_r521 /usr/local/weather

In the next article I’ll cover configuring it to upload to Twitter, Weather Undergound, The Met Office & to a website.

About these ads

61 thoughts on “Installing a USB Weather Station on a Raspberry PI Part 1

  1. Thanks for this article Peter – I’ve only just discovered WeatherUnderground and my immediate thought was how to get the Pi to upload data. A visit to Maplins is in order :)

    • petermount1 says:

      I’ve not had chance to write the second part yet which covers the config but for weather underground its really simple.

      In fact when I did the upgrade to the pi the newer versions of pywws actually supports thee Met Office WOW system as well which I’ll also cover.

      Twitter is slightly trickier but once done works well also.

      The only thing not working right is uploading to a website, it works ok hourly but it should also be working every 15 minutes but it’s not.

      Hopefully I’ll get that next part done next week.

  2. Dave says:

    Excellent article – managed to install and get working upto the point of data coming into pi with the command testweathersation– Data comes in but when I try to move to data it creates a weather.ini not a dat file – so no Data yet….

  3. […] the first article I covered how to install a weather station on a Raspberry PI. In the second part I’ll cover […]

  4. Bosstiger says:

    Reblogged this on Gigable – Tech Blog.

  5. slowtarget says:

    Check for the latest version of Cython – 0.17 was released on 1 Sep.

  6. slowtarget says:

    Great article, can’t wait for part 2… :)

  7. joe mccauley says:

    tried this on my pi (model B with 256mB & the 2012-09-18 rasbian wheezy image.) No matter what I do, I get an error when I do the following:

    ‘sudo python setup.py’ install from the ~/work/cython-hidapi directory.

    it appears to go well until building hid.o when I get a warning that a variable ânum_devâ is set but not used.
    Then when it is working with hid.so, I get:

    /usr/bin/ld cannot find -ludev
    collect2: ld returned 1 exit status
    error: command ‘gcc’ failed with exit status 1

    Any help appreciated

    • joe mccauley says:

      Should also say I’m working via ssh.

    • Jay R says:

      There is an incorrect path in the setup.py file. When changing the libusb path with “vi setup.py”, you will also need to change the library path from ‘i386-linux-gnu’ to ‘arm-linux-gnueabihf’.

      You’ll also need to move the libudev.so.0 file from /lib/arm-linux-gnueabihf/ to /usr/lib/arm-linux-gnueabihf/

      i.e:

      $ sudo cp /lib/arm-linux-gnueabihf/libudev.so.0 /usr/lib/arm-linux-gnueabihf/libudev.so

      I had the exact same issue and this got it going.

      • petermount1 says:

        I’ve been meaning to look at udev as I knew that was behind the permissions problem but not got round to it. I’ll give that a go here as I’ve been doing some tweaking to the setup.

        I’ve now got it posting live (every few minutes) but twitter seems to have broken overnight . Once I’ve got that fixed I’ll finally post those changes.

      • Ryan says:

        I had to run
        sudo apt-get install libudev-dev
        to overcome the cannon find -ludev error

    • Jordan says:

      There is an incorrect path in the setup.py file. When changing the libusb path with “vi setup.py”, you will also need to change the library path from ‘i386-linux-gnu’ to ‘arm-linux-gnueabihf’.

      You’ll also need to move the libudev.so.0 file from /lib/arm-linux-gnueabihf/ to /usr/lib/arm-linux-gnueabihf/

      i.e:

      $ sudo cp /lib/arm-linux-gnueabihf/libudev.so.0 /usr/lib/arm-linux-gnueabihf/libudev.so

      I had the exact same issue and this got it going.

  8. joe mccauley says:

    I got it working earlier this morning using additional instructions given here https://github.com/yfory/weather. They gave a few extra steps to be done if there was an error at the stage I mentioned earlier.

    Is this essentially the same as you guys did? I’m a total newbie at linux stuff. I also had tried the cython 0.17 rather than 0.16, but that did not help. I finally got the TestWeatherStation module to work.

    No w to do battle with getting it operational as a weather station. Have any of you gotten jQuery to run on a pi? I’m currently running my station from my desktop & have a set of webpages that I’d like to offload to the pi. They use jQuery to do the plots & I’d rather not re do the site if possible.

    • petermount1 says:

      Personally I’ve not seen that site so need to take a look.

      As for jQuery, that runs in the browser (unless there’s a server version I’ve not known) so it should be useable on the pi as all it’ll be doing is serving it to the browser.

    • Jordan says:

      Honestly, I’m simply using pywws as an uploader for Weather Underground, then monitoring the station from there. Works great.

  9. […] The raspberry can be the perfect for a weather station, a nice project about this can be found on this Blog […]

  10. […] his blog, Peter Mount explains the necessary raspian changes and in the 2nd part he also covers uploading […]

  11. […] The RPi has since be used to power everything from home-made jukeboxes to baby monitors to miniature near-space crafts and digital weather-stations. […]

  12. petermount1 says:

    When I got that slew of trackbacks this morning I was wondering what was going on. It seems it’s down to this article over on CNN

    http://edition.cnn.com/2012/12/21/tech/innovation/raspberry-pi-computer-upton/

    It has a short list of uses for the RPi and links right back to here when it mentions ditial weather-stations.

  13. Mike says:

    do you recommend any other weather stations? I don’t see N96FY USB Wireless Weather Forecaster on maplin anymore.

  14. Mike says:

    Thank you. I’m in the States so I don’t have access to a local store. Amazon though is global :)

    Thank you again. Nice little project i can work on with my son. weather station and some Raspberry Pi.

  15. Mark Pepper says:

    Peter
    For you and your readers Clas Ohlson sell the same weather station and it goes down To£46 from £86 around Christmas time. I purchased a second for spares because the transmitter unit tends to fail. Clas Ohlson also sell spares.

    http://www.clasohlson.com/uk/Weather-Station/Pr363242000

    Can’t wait for part 2, keep,up,the good work and I’ll be replacing man windows/Cumulus software combo as soon as possible.

    Mark

  16. Antonio Minn says:

    Thank you for your guide! But I have a question… This solution should works with WH1081PC station? (see the link: http://www.kingshopitalia.com/stazione-meteo-wireless-datalogger-wh1081pc-palo-con-sensori-e-pannello-solare-p-267.html).
    I need to buy a station who works perfectly with raspberryPI…

    Thanks

  17. John Wheeler says:

    Hello
    Please can you help.
    First I should say that I am a complete novice with Linux.
    I have got as far as cython hidapi.When I type vi setup.py it seems to hang.
    I have noted comments above but I don’t know how to follow the solutions given.
    How do I change the library path as mentioned by Jordan and Jay R
    Also how to change the path to libusb.
    Step by step instruction on the section before the PYWWS section would be most helpful.

    With this help I will put my weather station on my web site. http://www.hambledencottage.com

    Thank you

    John

  18. steve says:

    This might be a silly question, but once this is all done how does the weather station communicate with the Pi?

    • petermount1 says:

      In this instance over USB. The control panel exposes all of the recorded data which pywws and other software then reads periodically.

      At some point I’m going to look at linking the pi direct to the outside hardware. Someone has already done that using a radio receiver attached to gpio bypassing the console.

  19. Luke Cassidy says:

    Guide to using Raspberry Pi with Met Office WOW site… http://trastle.github.com/rpi-weather/gettingStarted.html

  20. Greg says:

    As someone mentioned above, i also have one of the Maplin setups, but the TX unit failed. has anyone thought of connecting the sensors directly to gpio ? (it’s on my list of jobs, but swmbo keeps moving things above it !)
    Thanks Greg

    • petermount1 says:

      Someone did post a link earlier where with a circuit which does exactly that. It consists of a suitable radio receiver which picks up the signal from the external sensors. As each transmitter has a unique I’d you could then add additional stations.

      I have also thought about looking at 1-wire as most of the sensors use that and you can easily get them.

    • petermount1 says:

      Ignore the first part of my response (damn lurg) I misread tx for rx. The second part is OK though, take a look at 1-wire.

  21. Nicklas says:

    When I connect the weather station to the raspberry via usb, it looses Connection to the sensors. Anyone else having this problem?

    • petermount1 says:

      I’ve not had that problem.

      How close is your pi to the receiver? If is close our between it and the sensors it could cause interference.

      The distance of the sensors & what’s between them and the receiver could also be a factor.

      Does the problem happen if you put both close to the sensors?

  22. […] בעזרתו, כמו לדוגמה שולחן הקפה האינטרקטיבי, מחשב נייד, תחנת מזג האוויר, שרת-מחשב ענן, ואף תחנת רדיו […]

  23. […] megoldás létezik, de a PYWSS állítólag működik is. Kell hozzá néhány library telepítés és egy pywws nevű Python script gyűjtemény (3), amit […]

  24. nick says:

    what kinda of information should I be seeing when I run sudo python /usr/local/weather/TestWeatherStation.py

    it seems to me like it just hangs.

    When I unplug and plug back in my weather station it crashes the program.

  25. laurent says:

    Hello,

    I installed successfully pywws on my Rasp. All is connected with Wifi dongle to my website http://weather.solarcamlab.com

    Also, I had a solarcamera wifi (or GSM) to get regular picture.

    Now, I must admit the visual of the pywws on the website is not very attractive.
    Any idea to improve the graphic page and more visual ?

    thanks,

    Laurent

    • petermount1 says:

      Yes the graphs are pretty basic.

      You could look at the templates but I’d doubt you’ll get anything looking much better.

      As part of another project I’m looking at generating html5 graph’s of various data so when I’ve done that I’m gong to look at replacing them with something better looking.

    • I’m trying to the do the same thing, connect my Rasp Pi to my weather station. I’ve dabbled in linux and pyuthon the past but I consider myself a newbie at it. Please forgive my simple question.

      My question is, can I just install pywws on the Pi and get it work without compiling Cython and the Dev environment that you outline at the beginning of your article?

      For the record, I’m running the B version of Pi and the latest Raspbian distro (NOOBs V1.1)

      • petermount1 says:

        The problem I have is my pi weatherperson is so old it’s pre-raspian.

        When twitter failed last week I was going to rebuild it from scratch but in the end just updating tweetie was enough.

        I’m not certain if you can bypass cython. I suppose if the current raspian has cython & it’s version is high enough then you should be OK.

        I really need to find the time to do the rebuild. Then not only will I get an up to date os but also IPv6, it’s the only pi I have that’s not got a global ip address.

  26. Thanks for the quick reply Peter. In the end I had to compile Cython and have been working through your fantastic tutorial!

  27. […] ports built in. A quick search revealed that Peter Mount has done all of the hard work already in a part 1 and part 2 tutorial. The tutorials are excellent, well written and unlike most Linux projects I […]

  28. […] Une station météo. […]

  29. Marko says:

    thank you verry much for this nice tutorial.
    i’m thinking about installing a windturbine at home to generate my own electrical energy, so it is usefull to log the wind data and analyze it.
    For this usage it is usefull to get one file with all the data in. Never programmed python before, but i was able to edit the Hourly.py to do this job. The generated File could be analyzed there:

    http://www.kleinwindanlagen.de/tools/powerpredictor/

    here tho code i’ve added to the python file:

    def main(argv=None):
    txtFiles = []
    for root, dirnames, filenames in os.walk(“/usr/local/weather/data/raw”, topdown=True):
    for filename in filenames:
    if filename.endswith(‘.txt’):
    outfileName = os.path.join(root, filename)
    txtFiles.append (outfilename)
    outputFile = open(“/var/www/combined.txt”, “w”)
    for data in sorted(txtFiles):
    readFile = open(data, “r+”)
    fileData = readFile.read();
    readFile.close();
    outputFile.write(fileData);
    print data
    outputFile.close();

  30. […] Install and configure pywws and dependencies as per this or more recently this. […]

  31. […] 天气预报站:http://blog.retep.org/2012/07/30 … aspberry-pi-part-1/ […]

  32. Jose Gouveia says:

    Hi, I followed your tutorial step by step and everything is ok until cython-hidapi instal.

    I have changed the libusb-1.0 path and when I run the code “~/work/cython-hidapi $ sudo python setup.py install” I get this.

    >Traceback (most recent call last):
    > File “setup.py”, line 3, in
    > from Cython.Distutils import build_ext
    >ImportError: No module named Cython.Distutils

    What can I do to overcome this step? I don’t know much of programming… sorry

    I am installing this in a raspberry pi b+

    Regards

    • Jordan says:

      This tutorial is now a few years old, so my only advice is to research how the Cython package has changed over time.

      The error implies that Cython.Distutils has been renamed or moved.

      • petermount1 says:

        Yes it is but also how usb is supported in pywws had changed as well since then, mainly making usb more stable.

        My best advice is to go to the pywws site for the latest instructions or alternatively ask on the pywws Google group which is linked from there.

  33. […] online that have great tutorials. These projects range from an in-car computer, an arcade table, Weather station, and even a cloud server. What ever you choose to do with your Pi I’m sure that you’ll […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,776 other followers

%d bloggers like this: