Showing posts with label Weather Station. Show all posts
Showing posts with label Weather Station. Show all posts

Sunday, 16 January 2011

Personal Weather Station using BifferBoard

I have managed to re-compile openWRT to run on the bifferboard, and include python, libusb and pyusb in the main root directory.   I also included the wget utility, because I thought it would come in useful, plus a few other potential future extensions (lighttpd web server and wireless LAN support).
This fits on the bifferboard onboard flash memory, with about 1MB to spare.

I created a /home/weather directory and extracted a recent pywws tar archive into it.   I was very pleased that running TestWeatherStation.py produced a table of numbers as expected, so it looks as though the bifferboard is talking to the weather station ok.
Here it is:


Set up the initial weather database by doing
cd /home/weather 
python pywws/pywws/LogData.py -vvv /home/weather/data
This creates /home/weather/data/weather.ini and a directory /home/weather/data/raw which contains the raw data.
Run Hourly.py for the first time to process the data, and set up the weather.ini file ready for customisation:
pywws/Hourly.py /home/weather/data
Customise /home/weather/data/weather.ini to do what you want it to do - in my case update weatherunderground....

All is looking promising here - seems to send the update ok on an hourly basis.  There are two problems though:
  • There is not much disk space left now I have added all of January's weather data (256kB ish)
  • I am concerned that I will wreck the flash chip on the bifferboard with all this writing.
One option is to store the weather data in a ram disk and just accept that after a power-off it will need to re-initialise itself - not sure how pywws will cope with this - I will need to load some default weather.ini file from flash every time it boots, then let it update itself as best it can.

As a quick alternative I have found an old 256MB SD card and created an ext3 filesystem on it.  This detects as /dev/sda1 when plugged into the bifferboard.   I have modified /etc/rc.local to mount this as /home/weather.  This should solve my full filesystem problems.  [Note:  I used an ext3 filesystem because my openWRT build could not detect ext2 - this was a bit of a surprise because I thought you got ext2 support free with every Linux kernel...].
Then it is just a matter of a cron job to do the hourly updates - crontab -e, then add:
13 * * * *       python /home/weather/pywws/Hourly.py -v /home/weather/data >> /home/weather/Hourly.log 2>&1
If it works, you should continue to see the weather in our back garden at: http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IHARTLEP2.

Mistake 1:  If you put an SD card into the dual USB bifferboard, it disables one of the USB ports.  This is bad if it was the one the weather station was connected to....

Mistake 2:  Believe people when they say the clock on a board is no good.  The Bifferboard clock is no good.  Not only does it loose its time when powered off, but it drifts - by a few minutes an hour.  This meant that pywws got confused about when it should update weatherunderground, because it thought time had suddenly gone back to 2009....   To avoid this I compiled ntpclient as a package and downloaded it onto the bifferboard.   I now have it set to be called once on boot, then every 10 minutes by a cron job.  This should keep it somewhere close - just hope the time server owner doesn't mind - If I get a complaint I will have to set up my own time server...


Saturday, 8 January 2011

Building openWRT

I have got a little bifferboard single board computer which I intend to use to run pywws to send data from our weather station to the weather underground site on the internet.

The bifferboard comes installed with a very small linux distribution called openWRT.   It has a very small python installed, but no python USB support.

I have struggled a bit to work out how the openWRT package system works - the official wiki is a bit confused about what the current version is called (kamikaze or backfire).  It implies you can add packages by downloading them from svn, but this didn't seem to do anything.
I found a useful forum post here, which seems to be the best set of instructions.
You can do

./scripts/feeds update -a
This downloads the list of packages, but does not do anything else.
To get the buildroot system to compile it for you you need to 'install' it using:
./scripts/feeds install python 
./scripts/feeds install pyusb
You can then do "make menuconfig" and python and pyusb are shown to be compiled as packages "".
'make' actually compiles it.
I'll update this when I work out how to add these to the firmware image...

Wednesday, 29 December 2010

Personal Weather Station using NSLU2



While I wait for my new bifferboard to be delivered I thought I would get the weather station working and updating to weatherunderground.com using a Linksys NSLU2 that I have available.
The NSLU2 is already configured to run Linux.  There are quite a few varieties of NSLU2 linux, and I think this one was called OpenSlug when I installed it, but it now seems to be called SlugOSBE.
When I first set it up there was no python package available for it, so I had to write my utility meter monitoring program using Perl (yuk!).
Fortunately there is now a repository at http://ipkg.nslu2-linux.org/feeds/optware/slugosbe/cross/unstable/ that includes python packages.
To get python running (with USB support) on the NSLU2 I had to download the following packages from the repository, and install them with ipkg install .ipk:
libusb, libdb, libstdc++,ncursesw,readline,sqlite_3, zlib, python25, py25-usb

The python distribution did not put an executable in /usr/bin, so I had to do
ln -s /opt/bin/python2.5 /usr/bin/python

With all this installed I could plug the weather station into the NSLU2 (via a USB hub in my case) and pywws just worked.
I hope the bifferboard is as easy!

Tuesday, 28 December 2010

Personal Weather Station

I have just bought my wife, Sandie a personal weather station from Maplin.  It is a much better one than the simple one that broke recently - it has external humidity as well as temperature, plus wind speed and direction and rain detection.  Most importantly it has a USB connection so we should be able to connect it to an internet weather network so it can appear on our iGoogle home pages.

The maplin version is apparently a re-branded WH1080PC weather station - I chose this one rather than a more modern one because people have managed to get it working with Linux - I want to use a very low power single board computer to interface it, rather than a big PC running Windows.

I have chosen a bifferboard single board computer because it is cheap and has both USB and ethernet connections (I would have liked wireless lan too, but could not find something to do that, so I got the two USB port version of bifferboard, so will have a go at adding a USB wireless network interface card to it later).
My original idea was to use some software called meteoplug because you can buy a bifferboard with that already installed, so I know it would work.  However, when I looked into it, it is a subscription service that is not open source - all I really want to do is obtain data from the weather station and send it to weatherunderground, which can not be that difficult.
Fortunately there is an open source project, pywws, which is compatibly with the WH-1080PC weather station.
I thought it best to get it going on a desktop linux set-up first, then try to get it working on the single board computer.
From my Ubuntu 10.10 laptop I did:
svn checkout http://pywws.googlecode.com/svn/trunk/ pywws
sudo apt-get install python-usb
cd pywws 
python TestWeatherStation.py
Initially this gave an error "IOError: Claim interface failed", so I tried:
sudo python TestWeatherStation.py
Success - a string of numbers, and no errors!

To get rid of the requirement to run the program as root you have to tell 'udev' to give other users permission.
lsusb reports the vendor and product ID of the device (1941 and 8021 respectively), but this is actually reported as a USB missile launcher rather than a weather station.
I added a file called 05-weatherstation.rules to /etc/udev/rules.d, which contained the following line:

SUBSYSTEM=="usb", ATTRS{idVendor}=="1941", ATTRS{idProduct}=="8021", MODE:="0666", GROUP:="usb"

I also added a line to /etc/group to create the 'usb' group, and made myself a member of that group.
Re-started udev with 'sudo service udev restart', and now the test works without being root (note the colon in 'MODE:=' - it is very important!

pywws seems to work suspiciously well - creating a data directory (~/weather/data) and running

pywws/LogData.py -vvv ~/weather/data/
creates a file with some convincing looking numbers in it.   I have created a weather station on weatherunderground, so I think the next thing to do is install the weather station outside, then try to use pywws to send data to weatherunderground.