Archive for May, 2010

Weather Alert Script for your Home Server

May 23rd, 2010 | 10:28 pm cdt

With the often active tornado season in Middle Tennessee I’ve been meaning to buy a weather radio. But first I wanted to see if my home server could do the job for me. Using beep, cron, and the weather API from Weather Underground, I’ve crafted a homebrew weather alert system.

How it works: Utilizing cron, a PHP script is run every ten minutes retrieving the number of active weather alerts for a specific zip code. On most days the alert count is zero. However, if an alert is active, (a severe thunderstorm watch or a tornado watch, for example) cron starts running a separate PHP script every 1 minute looking specifically for severe thunderstorm warnings or tornado warnings.

If a watch is active, the server uses beep to send out a specific sound.

beep -f 75 -l 3000

If a warning is active, beep outputs a different sound.

beep -f 900 -l 1500 -r 4

As it happens, our server is just off the kitchen, so we can hear the beeping from the main part of the house.

Here is the code:

<?php
function pullWXAlerts() {
  $zipCode = 37086; // Your Zip Code
  $wxAlerts = "http://api.wunderground.com/auto/wui/geo/AlertsXML/index.xml?query=".$zipCode; // Weather Underground API
 
  $xml = simplexml_load_file($wxAlerts);
  $alertCount = count($xml->xpath(‘//AlertItem’)); // Counting the number of active alerts.
 
  echo "\nActive Alerts: ".$alertCount."\n\n";
 
  $alerts = array();
  if ($alertCount > 0) {
    echo "The following alerts are active for ".$zipCode.":\n";
    foreach($xml->xpath(‘//description’) as $alert) {
      $alerts[] = $alert;
      echo $alert."\n";
    }
    shell_exec(‘beep -f 75 -l 3000′); // Beep if an alert exists
    $wxAlerts = print_r($alerts,true);
$mailBody=< <<_ORDER_
The following alerts are active for the $zipCode zip code:
   
$wxAlerts
 
_ORDER_;
 
    mail(‘user@domain.com’,‘WX Alerts’,$mailBody);

  }
  echo "\n";
 
  // If alerts exist, start checking for additional warnings every minute.
 
  $lsResult = shell_exec(‘ls /etc/cron.minutely’);
  $f = strstr($lsResult,‘wx-warn’);
  if (($alertCount > 0) && ($f == false)) {
    echo "Copying warning script to /etc/cron.minutely.\n";
   
    // Copy our script to be run once a minute into /etc/cron.minutely
    shell_exec(‘cp /home/user/wx-alerts/wx-warn-min /etc/cron.minutely/’);
  } else if (($alertCount == 0) && ($f == true)) {
    echo "Removing script from /etc/cron.minutely\n";
   
    // If no alerts exist, remove our script from /etc/cron.minutely
    shell_exec(‘rm /etc/cron.minutely/wx-warn-min’);
  }
}

pullWXAlerts();

?>

Above is the script that looks for watches every ten minutes. If watches exist, a second script is copied over to to the cron folder and is run every minute. I’ve added the functionality to also email myself if an alert exists.

This is the script that runs every minute if a weather alert is active:

<?php
function pullWXAlerts() {
 
  $zipCode = 37086; // Your Zip Code
  $wxAlerts = "http://api.wunderground.com/auto/wui/geo/AlertsXML/index.xml?query=".$zipCode; // Weather Underground API
 
  $xml = simplexml_load_file($wxAlerts);
  $alertCount = count($xml->xpath(‘//AlertItem’)); // Counting the number of active alerts.
 
  echo "\nActive Alerts: ".$alertCount."\n\n";
 
  $alerts = array();
  if ($alertCount > 0) {
    echo "The following alerts are active for ".$zipCode.":\n";
    foreach($xml->xpath(‘//description’) as $alert) {
      $alerts[] = $alert;
      echo $alert."\n";
      if ($alert == "Tornado Warning" || $alert == "Severe Thunderstorm Warning") {
        shell_exec(‘beep -f 900 -l 1500 -r 4′);
        echo "Beeping 4 times for ".$alert."\n";
        $warn = true;
        $warning = $alert;
      }
    }
    $wxAlerts = print_r($alerts,true);

    if ($warn == true) {       
$mailBody=< <<_ORDER_
The following warnings are active for the $zipCode zip code:

$warning

_ORDER_;
   
    mail(‘user@domain.com’,‘WX Warning Alert’,$mailBody);
}  
}
  echo "\n";
}
pullWXAlerts();
?>

Once again we’re getting an alert count. If an alert exists and it’s either a thunderstorm warning or a tornado warning, beep takes over and starts sounding the alarm.

I had to customize my crontab in order for the system to run a job every ten minutes as well as every minute. There is a lot of info about crontab on the interwebs.

Once cron is set up, you can call these files from a bash script like so:

#!/bin/bash

php /home/user/wx-alerts/pull-wx-alerts.php

A word of caution: While this system may work well for some, it’s likely not ideal for everyone. Some system beeps are very quiet. You’re also relying on computers to get the alert out. Not to mention your internet connection and power company. Personally, I’ll still be investing in a real weather radio, but this can act as a decent failsafe.


Filed under Weather
View Comments
Digg this

Flooding in the Bordeaux Area

May 6th, 2010 | 9:30 am cdt

Some coworkers and I volunteered with Hands On Nashville to help people clean-up from some of the flood damage in the Bordeaux, North Nashville area. Here are a few images from that part of town.

House moved off foundation
A house moved off its foundation by flood water. Hummingbird Rd. and Buena Vista Rd.

Flooded Road
Two lane road covered with water.

USN Fields
USN sports fields flooded.

Whites Creek and County Hospital Rd.
Whites Creek running over County Hospital Road in North Nashville near Briley Parkway.

Buckled asphalt on Tucker Rd. off W. Hamilton Rd.
Buckled asphalt on Tucker Rd. off W. Hamilton Rd. leading to a bridge over Whites Creek.


Filed under Weather
View Comments
Digg this

How High is Percy Priest Lake?

May 6th, 2010 | 9:05 am cdt

Precy Priest Lake/Dam has been holding back a lot of water to help prevent further flooding along the Cumberland River in Nashville. Yesterday morning I went down to the Hurricane Creek Boat ramp in La Vergne to see how high the water was.

As you can see, the entire ramp and parking area is still under water.

High water at Percy Priest Lake

Precy Priest from Google Street View
This is the normal view of Percy Priest Lake from Google Street View.


Filed under Weather
View Comments
Digg this

Historic Flooding in Middle Tennessee

May 1st, 2010 | 9:36 pm cdt

The flooding continues to worsen, with more rain expected on the way. Merredith and I were out in the rain most of the morning entering into the early afternoon, spending time in Fairview. We tried to stop for a late breakfast at the Loveless, but the wait would have been over an hour.

The rain and roads were just terrible along I-440 around 1:00. Traffic was slow and water was ponding. We stopped for lunch at the I-65 Harding exit and watched the rain continue to fall. On the way home from lunch we took Harding headed East to I-24. Water was pooling on Harding in multiple areas, traffic was slow. We decided to take I-24 back to La Vergne, but there was so much water on I-24 we got off at the very next exit which was Haywood Lane/Antioch Pike.

Antioch Pike turned out to be just as bad as the interstate; water over the road, completely blocking the road just beyond Hickory Hollow Parkway. What we didn’t realize at the time was that we were seeing the very beginnings of Mill Creek coming over its banks. On Mt. View Road the water was deep enough between the I-24 ramps and Old Franklin Road to submerge a motorist. We went around and called Metro.

Murfreesboro Road heading into La Vergne was equally flooded in spots, with motorists having to slow down to get through the water. Into La Vergne, Old Nashville Highway in front of the Co-Op and Behind the Dominos plaza was covered in water, and spots of Stones River Road were also covered.

Once we were home we began to see the full effects of Mill Creek submerging cars and trucks on I-24, Bell Road, Blue Hole Road and Antioch Pike. Had we stayed out a bit longer, waiting for that table at the Loveless, we likely would have been right in the middle of the flooding on one of those roads.

I was driving, so wasn’t able to snap any photos, but plenty of other folks did:

Photo of I-24 at Bell Rd. from WSMV: http://tweetphoto.com/20716205

Video of a school portable floating down I-24 at Bell Rd.: http://yfrog.us/49qsfz

Jackass truck driver causing floating cars to run into each other, threatening bystanders: http://www.twitvid.com/SZBE5 (I-24 at Bell Rd.)

Drivers braving flooded I-24 at Briley Parkway: http://www.twitvid.com/PXVVP

The Tennessee Traffic Cameras Widget caught several still image of the I-24 flooding.

Flooding at I-24 & Bell Rd.

I-24 Flooding

I-24 Mill Creek Flood

I-24 Briley Parkway Flood

I-24 Flooding

I-24 closed at Briley


Filed under Weather
View Comments
Digg this

Projects

Candor Gallery
Candor Gallery
Candor Gallery is an OS X Widget and Google Gadget that displays user submitted art.
Tennessee Traffic Cams
Tennessee Traffic Cams
Tennessee Traffic Cams is a widget that displays traffic camera feeds from across the state of Tennessee.
Language Design Group
Language Design Group
Language Design Group is a translation agency for all your foreign language needs.
Portfolio
Portfolio
My personal portfolio
Older Projects
Crissy's Roommate
PenceBook
Crissy's Roommate was a daily cartoon strip produced for the Daily Beacon from 2000-2002.
Hess Hall Webcam
Hess Hall Webcam
The Hess Hall Webcam captured the daily activities of Hess Hall.
Etc.
Browser Dream

The Ubuntu Counter Project - user number # 783