Welcome to the Weather Machine, by Ed T. Toton III. Contact info: necrobones@necronbones.com bones@necrobones.com http://www.necrobones.com/ http://www.necrobones.net/ As of this release, my weather station can be viewed at: http://banshee.necrobones.net/weather.shtml This set of programs is being distributed for free. Do what you want with it. Please show credit where credit is due. INTRODUCTION The Weather Machine is a perl script that is designed to read and log weather data via a serial port from a WMR-968 Oregon Scientific weather station. These can be purchased from a variety of locations on the net, including eBay. Log data is stored in flat files, and a one-line status file is written to every minute as well for current "real time" information. Two additional scripts are also included for accessing this data. The first is weatheroutput.pl, which takes command-line arguments to choose which numbers to display. This is particularly useful for use with MRTG, as that is what it was designed for (example MRTG configs are given below. For those who don't know, MRTG is a really nice free graphing package). The other script, weathertable.pl, generates an HTML table that can be used as a server-side include. Future versions may include CGI scripts to display historical data from the logs, but for now the logs are merely stored with no retrieval method included. Yes, not all of the design here is terribly robust or pretty, but it works, and that was the only design goal. :) Feel free to modify it for your particular needs. REQUIREMENTS A PC running linux, with perl 5, and the following perl modules: Device::SerialPort LWP::UserAgent HTTP::Request If you don't have them, you can always use cpan to obtain them, such as like this (executed as root): perl -MCPAN -e shell install Device::SerialPort install LWP::UserAgent install HTTP::Request INSTALLATION 1. Pick a directory, and put these files there. I use /www/weather, where /www is a symlink to my htdocs directory. It doesn't matter what you choose, as long as you edit the paths assigned at the top of all of the scripts accordingly. 2. Open up each *.pl script and edit the paths accordingly. :) While you're in there, make sure weathermachine.pl has the correct serial device for your weather station. If you want it to send updates to The Weather Underground for you in real time, first set up an account at www.wunderground.com, and edit the username and password in the script accordingly. Also make sure the log path puts the logs where you want them, and that the other scripts are adjusted to the same location, if you choose to use them. 3. Put a line in your rc.local or other startup script to make sure it starts up at boot, and give it a manual run to make sure it's all working. Here's the invocation I use in rc.local: /www/weather/weathermachine.pl You'll notice there are no arguments. All configuration is done at the top of the script itself. 4. You may wish to add a cron-task to ensure it keeps running, just in case it terminates or gets killed for some reason. Here's what I use, along with a line to tar up backups of the data: # Check to make sure weathermachine keeps running */10 * * * * cd /www/weather ; ./weathermachine.pl > /dev/null & 15 1 * * * cd /www/weather ; sleep 30 ; tar cvfz weather-backup.tar.gz * > /dev/null The weathermachine will not run twice, assuming it's program-name variable is set correctly. :) 5. If you wish to use weathertable.pl, put it (or symlink it) somewhere where it can be executed by apache as a server-side include, like this: 6. Enjoy! MRTG GRAPHS MRTG (or "Multi Router Traffic Grapher") is a nice graphing engine that can be used for a variety of purposes. For information on how to obtain/install it, please visit it's official site: http://people.ee.ethz.ch/~oetiker/webtools/mrtg/ While primarily intended to graph SNMP data, it can also be used to graph locally available real-time data. This is where the script called weatheroutput.pl comes in. In the weathermachine log directory you set up, there will be a status file called 'weathermachine.status' which is overwritten once per minute by the weathermachine.pl daemon. Thus, polling this file could be treated as real-time weather information, accurate to within a minute. Below are the /etc/mrtg.cfg configs that I use. Obviously you will need to edit them to suit your purposes. weatheroutput.pl is a script that outputs numbers that are drawn from the realtime status created by weathermachine.pl. The command line arguments tell it what to output, and it understands some extremely rudimentary math on the command-line. Here are the configs: Target[outdoortemp]: `/www/weather/weatheroutput.pl otf odf` Options[outdoortemp]: nopercent,growright,gauge,noinfo,withzeroes Title[outdoortemp]: Outdoor Temperature and Dew Point PageTop[outdoortemp]:

Outdoor Temperature and Dew Point

MaxBytes[outdoortemp]: 1000000 YLegend[outdoortemp]: Outdoor Temp/DewPt (F) ShortLegend[outdoortemp]: F LegendI[outdoortemp]:  Temperature: LegendO[outdoortemp]:  Dew Point: Legend1[outdoortemp]: Outdoor Temperature Legend2[outdoortemp]: Outdoor Dew Point Legend3[outdoortemp]: Peak Outdoor Temperature Legend4[outdoortemp]: Peak Outdoor Dew Point YSize[outdoortemp]: 150 XSize[outdoortemp]: 600 WithPeak[outdoortemp]: ymw Target[indoortemp]: `/www/weather/weatheroutput.pl itf idf` Options[indoortemp]: nopercent,growright,gauge,noinfo,withzeroes Title[indoortemp]: Indoor Temperature and Dew Point PageTop[indoortemp]:

Indoor Temperature and Dew Point

MaxBytes[indoortemp]: 1000000 YLegend[indoortemp]: Indoor Temp/DewPt (F) ShortLegend[indoortemp]: F LegendI[indoortemp]:  Temperature: LegendO[indoortemp]:  Dew Point: Legend1[indoortemp]: Indoor Temperature Legend2[indoortemp]: Indoor Dew Point Legend3[indoortemp]: Peak Indoor Temperature Legend4[indoortemp]: Peak Indoor Dew Point YSize[indoortemp]: 150 XSize[indoortemp]: 600 WithPeak[indoortemp]: ymw Target[humidity]: `/www/weather/weatheroutput.pl irh orh` Options[humidity]: nopercent,growright,gauge,noinfo,withzeroes Title[humidity]: Indoor and Outdoor Relative Humidity PageTop[humidity]:

Indoor and Outdoor Relative Humidity

MaxBytes[humidity]: 1000000 YLegend[humidity]: Rel. Humidity (%) ShortLegend[humidity]: % LegendI[humidity]:  Indoor Humidity: LegendO[humidity]:  Outdoor Humidity: Legend1[humidity]: Indoor Relative Humidity Legend2[humidity]: Outdoor Relative Humidity Legend3[humidity]: Peak Indoor Relative Humidity Legend4[humidity]: Peak Outdoor Relative Humidity YSize[humidity]: 150 XSize[humidity]: 600 WithPeak[humidity]: ymw Target[pressure]: `/www/weather/weatheroutput.pl bmb-950 smb-950` Options[pressure]: nopercent,growright,gauge,noinfo,withzeroes Title[pressure]: Barometric Pressure (mb - 950) PageTop[pressure]:

Barometric Pressure (mb - 950)

MaxBytes[pressure]: 1000000 YLegend[pressure]: Baro Pressure (mb-950) ShortLegend[pressure]: mb-950 LegendI[pressure]:  Barometric Pressure: LegendO[pressure]:  Sealevel Pressure: Legend1[pressure]: Actual Barometric Pressure Legend2[pressure]: Sealevel Barometric Pressure Legend3[pressure]: Peak Actual Barometric Pressure Legend4[pressure]: Peak Sealevel Barometric Pressure YSize[pressure]: 150 XSize[pressure]: 600 WithPeak[pressure]: ymw Target[windspeed]: `/www/weather/weatheroutput.pl wam wgm` Options[windspeed]: nopercent,growright,gauge,noinfo,withzeroes Title[windspeed]: Wind Speed PageTop[windspeed]:

Wind Speed

MaxBytes[windspeed]: 1000000 YLegend[windspeed]: Wind Speed (mph) ShortLegend[windspeed]: mph LegendI[windspeed]:  Wind Average Speed: LegendO[windspeed]:  Wind Gust Speed: Legend1[windspeed]: Average Wind Avg Speed Legend2[windspeed]: Average Wind Gust Speed Legend3[windspeed]: Peak Wind Avg Speed Legend4[windspeed]: Peak Wind Gust Speed YSize[windspeed]: 150 XSize[windspeed]: 600 WithPeak[windspeed]: ymw Target[winddir]: `/www/weather/weatheroutput.pl wgd wgd` Options[winddir]: nopercent,growright,gauge,noinfo,withzeroes Title[winddir]: Wind Direction PageTop[winddir]:

Wind Direction

MaxBytes[winddir]: 1000000 YLegend[winddir]: Wind Heading (Deg) ShortLegend[winddir]: Deg LegendI[winddir]:  Wind Direction: LegendO[winddir]:  Wind Direction: Legend1[winddir]: Wind Direction Legend2[winddir]: Wind Direction YSize[winddir]: 150 XSize[winddir]: 600 Target[rainrate]: `/www/weather/weatheroutput.pl rrm rrm` Options[rainrate]: nopercent,growright,gauge,noinfo,withzeroes Title[rainrate]: Rain Rate (mm/hr) PageTop[rainrate]:

Rain Rate (mm/hr)

MaxBytes[rainrate]: 1000000 YLegend[rainrate]: Rain Rate (mm/hr) ShortLegend[rainrate]: mm LegendI[rainrate]:  Rain Rate: LegendO[rainrate]:  Rain Rate: Legend1[rainrate]: Average Rain Rate (mm/hr) Legend2[rainrate]: Average Rain Rate (mm/hr) Legend3[rainrate]: Peak Rain Rate (mm/hr) Legend4[rainrate]: Peak Rain Rate (mm/hr) YSize[rainrate]: 150 XSize[rainrate]: 600 WithPeak[rainrate]: ymw Target[raintotal]: `/www/weather/weatheroutput.pl rtm rtm` Options[raintotal]: nopercent,growright,noinfo,gauge,withzeroes Title[raintotal]: Rain Total mm PageTop[raintotal]:

Rain Total mm

MaxBytes[raintotal]: 1000000 YLegend[raintotal]: Rain Total (mm) ShortLegend[raintotal]: mm LegendI[raintotal]:  Rain Total: LegendO[raintotal]:  Rain Total: Legend1[raintotal]: Rain Average Total mm Legend2[raintotal]: Rain Average Total mm Legend3[raintotal]: Rain Peak Total mm Legend4[raintotal]: Rain Peak Total mm YSize[raintotal]: 150 XSize[raintotal]: 600 WithPeak[raintotal]: ymw