When I was a boy we had a maximum/minimum thermometer and a rain gauge in the garden. Logging the data accurately relied upon resetting the thermometer and emptying the rain gauge at the same time each day. Technology has moved on and it is now possible to cheaply have your own weather station recording temperature, humidity, rainfall and wind data, and to be able to view and analyse it via the internet without leaving your sofa. If you buy an off-the-shelf system then this will set you back a few hundred pounds, however with a little work you can build your own for just a few quid over a hundred. In this post I describe how I have done this and provide a few pointers so you can do the same.
You will need to be connected to the internet and be able to connect to it via Ethernet cable or wirelessly. Also required is monitor or TV that you can pluyg an HDMI output into. I’m also going to assume that you have a USB keyboard that you can use during the setup.
What you will need
Weather stations with USB connectivity can be purchased relatively cheaply nowadays. Other projects from which I have utilised information have used a Maplins weather station available for £99.99, if you buy one when it is on offer then you may get one for £59.99, or better still you might be lucky enough to get a refurbished one for £44.99 – which is what I did. The station comes in two parts: the sensors and wireless transmitter and the touchscreen receiver panel. If you are in a hurry it is worthy shopping around as you can also buy the same station on Amazon
The first thing to do is to assemble the sensors and set them up outside. The location needs to be somewhere where the measurements are not distorted by the surrounding environment. Usually you would want to locate your station in the middle of a grassy field, obviously often not practical for the amateur! The Met Office guidelines are available here. Here is a picture of my station with the instruments attached to the top of a post. Since taking the photo I have cut the hedge(!) and will raise it up a few feet in due course.
The next thing to do is to power up the receiver unit. There is not much to be done to set it up other than set the right time and the correct relative pressure, assuming it is within range it will quickly pick up the signal from the sensor unit. So, you now have a weather station, time to get it on the internet!
The components to make the Raspberry Pi system
Your own requirements and components may vary, but here are the components that I am using. I bought them all separately rather than as a kit since it is probably cheaper to do so and you get a tailored solution. I bought all of my components from Ebay as I saved a few pennies that way, but in the table below I’ve added Amazon links (which are less transient) so you can see what I am talking about.
|Component and Link||Cost||Notes|
|£31||Make sure that you get the latest version available.|
|£5 or less||Choose your favourite colour!|
SD Card with Raspberry Wheezy
|£8.75||I’d recommend at least 8 GB. For convenience buy one pre-installed with the latest version of Raspbian Wheezy.|
|£5||These are so cheap nowadays. I bought a 5 metre one for convenience.|
|£3.50||Even if you will be connecting wirelessly you will probably need an Ethernet cable to get things up and running. I used one I had lying around, but long ones are dirt cheap nowadays.|
|£5 and up depending on number of ports||You will only need this if you will be using more than two USB peripherals. If the Pi isn’t going to be WiFi and you don’t hanker after booting up the desktop GUI (hence you might want a mouse) then you will only be plugging in a keyboard and the weather station – in that circumstance you won’t need a hub. I bought an unpowered one and then had to swap with the powered one on my desktop. Don’t make this mistake, spend a couple of extra pounds and buy a powered one.|
USB WiFi adapter – very (too?)cheap
|£4||It is a well known fact that a Raspberry Pi won’t be able to reliably power a WiFi adapter, except of course I didn’t realise this well known fact until after I started to experience problems. So, either get a very cheap one and plug into your powered USB hub, or buy the alternative adapter below.|
USB WiFi adapter – cheap (and good)
|£8||The Edimax adapter is still cheap by historical standards and drawing less power should work plugged into the Raspberry Pi directly.|
|£2||I really don’t know how effective these are in the Raspberry Pi, but for a couple of quid why not?|
After you’ve assembled your list, do just double check you couldn’t buy it all cheaper in a kit!
Putting it together
Next, put the Raspberry Pi in its case. If you have the one pictured note that you need to put one edge of the card in first under the plastic ridge rather than dropping it straight in. Keep your greasy, static-charged fingers off the electronics.
If you are adding the three heat sinks to aid cooling then now is the time to stick them on the relevant chips – that’s the three square, black items. Good luck peeling the plastic off the sticky stuff.
Now slot in the SD card and plug in your assorted cables. If you are going wireless then plug your WiFi adapter into the USB hub, if not then the USB keyboard and weather station can both go straight into the Pi USB sockets. Turn the power on!
Hardware having now been dealt with, from here the software path to internet weather station success is well trodden and therefore I am not going to regurgitate the wise words of those who I followed, but I will provide links and pointers I came across.
A brilliant guide to getting started is here. I would recommend following Step 1, then if you are using a WiFi adapter switch to getting it installed. For the RT5370 I found this page had the best tips. As for the Edimax, it came a few days after the other items, I just plugged it in and it worked without any further intervention from myself (if you have problems with it try this).
With the internet fully functional switch back to this guide and follow the steps to the bottom. Having got everything installed now all you have to do is get to grips with pywws. Do browse the excellent help pages – in fact you may want to do this before you start. As an aid here are some tips you might find useful:
- You will want to change the time interval to get updates from the station:
python -m pywws.SetWeatherStation -r 5).
- You will need to understand and change weather.ini. This includes how to automatically ftp to your website.
- You’ll need gnuplot for the plots to be drawn:
sudo apt-get install gnuplot
- Use “pywws.LiveLog” to get data from your station live.
- You will want to make sure that you weather station comes back to life after a software crash or power failure, so create a script like the one here and add a cron job (use “crontab -e” to edit the relevant file). I set this job to run every 15 minutes.
If you have set up pywws.LiveLog correctly then your processed data should be sent via ftp to your web server at regular intervals and from there you can use it directly on your site. My site uses WordPress so it is very straightforward to plop the code automatically generated straight into a page. Here is one way of doing it:
- Install a plugin like “Allow PHP in pages and posts” to execute PHP in a page.
- Use code like the following to include the generated code:
- Obviously include the PNGs the same way you would any other image:
<img alt="Last 24 hours of observations" src="http://www.yoursite.com/weather/24hrs_full_features.png" />
The final result
The output of the observations for Bartestree can be found here. I have done some validation against a second thermometer, a local weather station and collecting rain in a tin for a crude comparison of total rain amounts. It all seems to be within the accuracy expected.
I also added the latest Met Office rainfall radar image to this observations page and a link to my forecast page which pulls the Datapoint feed from the Met Office.