Tricking out WRT54G router
From EWiki
See http://svallens.com/eric/projects/61/tricked-out-wrt54g for overview.
Contents |
Software for LCD output
I settled on a set of shell scripts that use text files in /tmp/messages for putting information on the 16x2 LCD. The master program, messaged, is run by an init script at boot and cycles every message in /tmp/messages to the LCD for the specified number of seconds.
messaged
#!/bin/bash
mkdir /tmp/messages
echo $$ > /var/run/messaged.pid
if test -z "$1"; then period=0; else period=$1;fi
while true; do
for i in `ls /tmp/messages`; do
if [ `wc -l < /tmp/messages/$i` -gt 1 ]; then
/mmc/bin/printlcd2 < /tmp/messages/$i
else
/mmc/bin/printlcd < /tmp/messages/$i
fi
sleep $period
done
done
I then have a number of shell and perl scripts that dump weather and other information into /tmp/messages.
accumessage
Grab weather information from Accuweather.com and display high, low, current temperature, and current RealFeel temperature. Textutils aren't really the best choice for XML parsing, as I discovered.
#!/bin/bash pagedata=`wget -O - 'http://vwidget.accuweather.com/widget/vista1/weather_data_v2.asp?location=12180'` high=`echo $pagedata | tr '<' '\n' | grep wxf | head -n 1 | tr ' \t' '\n\n' | grep htmp | cut -d '"' -f 2 | tr -d '\n'` low=`echo $pagedata | tr '<' '\n' | grep wxf | head -n 1 | tr ' \t' '\n\n' | grep ltmp | cut -d '"' -f 2 | tr -d '\n'` temp=`echo $pagedata | tr '<' '\n' | grep wxc | tr ' ' '\n' | grep temp | cut -d '"' -f 2 | tr -d '\n'` realfeel=`echo $pagedata | tr '<' '\n' | grep wxc | tr ' ' '\n' | grep rft | cut -d '"' -f 2 | tr -d '\n'` firstline="Now: $temp RF: $realfeel" #buffersize=$((36 - `echo -n $firstline | wc -c`)) #buffcount=`seq 1 $buffersize` #buffer=`for i in $buffcount; do echo -n " "; done` secondline="High: $high Low: $low" echo "$firstline $secondline" > /tmp/messages/accu
roommessage
Grab the temperature from the 1-wire bus for inside and outside my room.
#!/bin/bash echo "Room: `cat /tmp/1wire/uncached/1F.F5ED04000000/main/28.D87939010000/temperature11 | tr -d " " | cut -b 1-4`" > /tmp/messages/room echo "Outside: `cat /tmp/1wire/uncached/1F.51ED04000000/main/28.C5B509010000/temperature11 | tr -d " " | cut -b 1-4`" >> /tmp/messages/room
today.pl
Perl is easy to get up and running on the WRT, and I found a pure-Perl XML parser. Fun times! This gets today's forecast message from the same accuweather feed, but actually parses the XML properly to do it. I let the crontab line send the output to a file in /tmp/messages.
#!/mmc/usr/bin/perl
use XML::TreePP;
my $treepp = XML::TreePP->new();
$tree = $treepp->parsehttp("GET" => "http://vwidget.accuweather.com/widget/vista1/weather_data_v2.asp?location=12180");
$day = $tree->{adc_database}->{forecast}->{day}[0]->{"-wday"};
print substr($day, 0, 3);
print ": ";
print $tree->{adc_database}->{forecast}->{day}[0]->{daytime}->{txtshort};

