I recently joined the ranks of the weather geeks and set up a personal weather station that reports readings to Weather Underground every minute.

Initially I just wanted a brief local weather report that I could display how I liked: temperature, wind, forecast for current day. This is really easy to get with the Weather Underground API.

But I wanted really local weather readings...

Searching around for personal weather stations I could talk to I found Lee's WeatherPi. Great idea, and nicely done. I had a Mac mini sitting around looking forlorn and neglected so I decided to put it to work reporting weather data.

Components

The weather station reports data wirelessly to an indoor controller with an LCD display. The controller has a USB port to get at weather data. A program that samples and uploads weather data runs on the Mac.

I used the awesome pywws toolkit to talk to the weather station. Among other things it can summarize data, generate pretty pictures, tweet, and upload to Weather Underground. The provided doc is excellent.

Setup

pywws does all the work here, I just had to configure it to run automatically on the Mac.

  1. Install Weather Station according to its doc and verify the indoor display controller is getting data.
  2. Follow the pywws Getting Started Guide. This gets your computer talking to your weather station. Use the default ~/weather directory as described, we will move it later.
  3. Follow the pywws Weather Service Guide to set up a weather underground account and send some weather data to it. The pywws doc has a section on setting up RapidFire updates which effectively gives you real time weather data. Pretty cool.

At this point you have weather uploads working on demand from the command line and updating your very own Weather Underground station. Spend a few minutes to bask in the glory of having your own online weather station. Now let's automate it.

Automating

I wanted this system to be hands-off and restart itself automatically in the event of a power failure. pywws can run continuously as a background job. On Unix systems including Mac OS X you can use cron and a lock file to roll your own daemon as described in the pywws docs. That's always felt a little kludgey to me. I prefer a well defined service daemon interface where you tell the OS "run this program at boot time and restart it if it exits". On Linux you can do this with upstart or systemd. I've used upstart and the like to set up daemons on Unix servers. Since I was using a Mac I thought it would be fun (?) to learn something new and do it "the Mac way", which is to use launchd.

I wasn't sure if this was going to be painful as you need to write a plist XML file and install it. I was happily surprised to find it to be simple and rather painless. The Apple Doc on launchd is quite good. It shows you how to setup scheduled jobs à la cron, and has a hello world example plist to configure a daemon that stays running all the time. Perfect. launchd lets you create what it calls user agents that run when a user logs in as well as system wide launch daemons that start when the machine boots and run as root. For this application we want a launch daemon that starts when the system boots.

Steps

Make sure that you have on demand weather updates working as described above before proceeding. Then stop any pywws programs you have running and move the weather directory to /var and make root own it:

sudo mv ~/weather /var
sudo chown -R root:wheel /var/weather

Download weather-station.plist. This is a small XML file that runs a single command as a daemon, in this case it is the pywws weather data logger.

Move the file to the system launch daemon directory:

sudo mv ~/Downloads/weather-station.plist /Library/LaunchDaemons
sudo chown root:wheel /Library/LaunchDaemons/weather-station.plist

Start the daemon manually:

sudo launchctl load /Library/LaunchDaemons/weather-station.plist

If all goes well you should see your Weather Underground station page update with live data. Bask a little more now that you have up to the minute weather reporting. Okay that's enough basking. One more thing to do.

Last Step

Shut down the Mac and leave it off for two or three minutes. If you have another computer or tablet, check your weather page that is now two or three minutes old. Now power up the Mac but don't log in to it yet. Your weather station page should once again start updating every 48 seconds. The weather station itself can log and store weather data at 5 minute intervals for 2 weeks. And pywws knows how to play catch up after an outage. So you have continuous weather data even if the power fails as long as the outage is not longer than two weeks. Ok now you can bask as long as you like.

Troubleshooting Notes

  • check for errors reported by pywws in the log file /Library/WeatherStation/weatherd-stderr.log
  • if the pywws log is empty that probably means that the launch daemon is not running
  • ps -ef | grep -i weather to see if the daemon is running
  • /var/log/system.log or the Console application should have more info if the daemon is misconfigured
  • check out the pywws discussion group mentioned in the pywws docs