Get the Weather on your HP 4200
I mentioned, here, that I wrote a program to put the weather on the HP 4200 in our office. The program uses the perl Geo::METAR module to parse METAR weather information from NOAA. You'll need to install the module if you don't already have it (and you probably don't). Install it using ActiveState's PPM for Windows and the CPAN program (or OS package manager) for everything else. You will also need to know your ICAO airport code and the IP address of your printer.
How does it know?
You can use some sort of cron job or the Windows "at" service to run it periodically. The METAR data doesn't actually change more than once an hour so more frequent updates won't buy more accuracy. This program requires a little more assembly than the earlier one but the comments in the source should be sufficient. The code itself was a 10-minute hack and is not intended to be lovely, but it has performed flawlessly for years now. The program targets the HP 4200 but it is very possible that it will work with other large display printers as well—it can certainly be modified to do so.
I like this one because it is hackish and useful at the same time.
NOTE: Windows users installing Geo::METAR via PPM may find that the temperature variables need to be edited. If you get errors you can try making them C_TEMP and F_TEMP. I haven't tracked down why this is true, but it appears to be.
You can use some sort of cron job or the Windows "at" service to run it periodically. The METAR data doesn't actually change more than once an hour so more frequent updates won't buy more accuracy. This program requires a little more assembly than the earlier one but the comments in the source should be sufficient. The code itself was a 10-minute hack and is not intended to be lovely, but it has performed flawlessly for years now. The program targets the HP 4200 but it is very possible that it will work with other large display printers as well—it can certainly be modified to do so.
I like this one because it is hackish and useful at the same time.
NOTE: Windows users installing Geo::METAR via PPM may find that the temperature variables need to be edited. If you get errors you can try making them C_TEMP and F_TEMP. I haven't tracked down why this is true, but it appears to be.
20 Comments:
Neat script...thanks! One problem I came across was that the temp variables are actually C_TEMP and F_TEMP (rather than TEMP_C and TEMP_F).
Otherwise it works great. I am using it on a Color LaserJet 3700 with a two-line display.
Cheers!
This is the coolest thing I have seen in at least a week. Way to Go!
We did this back in college and I'd completely forgotten about it until now. Thanks for the Perl script.
I plan to go check the docs for this, but is there any way to reset it to the original RDYMSG? I'd like to pull this at work but don't want them living with "WARRIOR NEEDS FOOD BADLY" for ever. The current RDYMSG has a nice border and check mark inside of it that I wouldn't know how to render.
LOL, brilliant! ;-)
Odd. The program works and perldoc Geo::METAR tells me:
TEMP_C
Temperature in Celsius.
TEMP_F
Temperature in Farenheit.
Which is how the script has it...
I set this up on the 4200 outside my office with my MacBook doing the hourly query via a launchd plist. Nerdy! I had to install XCode and Geo-METAR to get it working on OS X 10.4.10. Suffice it to say I had time and effort on my side.
I pointed it out to a first grade teacher at work who brought her class through the lab and she thought it was pretty cool, especially since it was 51 degrees F outside.
I really like the idea behind this project and your insert coin project because it uses a printer, which most of the time is sitting completely idle, to provide up-to-date information in an ambient but current manne, or to showcase perverse nerd humor. I love the idea of walking out of my office and being able to glance at the printer that is giving me real-time pertinent information.
Awesome, awesome hack...
Works on a 5500dn as well, neat stuff
Am I reading that wind display right? Southerly at the speed of sound?
I certainly hope not!
It is 5.754 not 5,754 , the "." is hard to see.
Further proof is that I am here to point this out.
what if I am behind a proxy? how do I supply that information?
i.e. proxy ip, port, user/pass
What if you need to connect to a proxy to get to the internet?
LWP::Simple respects the http_proxy environment variable. More information is in perldoc LWP::UserAgent.
If you can't work it out yourself, try visiting the #perl IRC channel on irc.freenode.net where you will find lots of helpful folks and maybe even stick around and learn perl.
It's my first time playing with perl, and I got an error: You suck. You tried to access something that is not here. at weatherPrinter.pl line 48
(in cleanup) You suck. You tried to access something that is not here. at weatherPrinter.pl line 0
I changed out the TEMP_C and TEMP_F for C_TEMP and F_TEMP, and that got rid of the first error but I still get this error: (in cleanup) You suck. You tried to access something that is not here. at weatherPrinter.pl line 0 I was successful with the HPSetDisplay.pl so I assumed that I'd be able to figure this one out...
Awesome hack. I noticed that the words are not always perfectly centered and it's because if the free space on a line is an odd number, half of it is something-and-a-half and the half never gets accounted for. I made a common function to add padding to all lines. See below.
sub pad
{
my $instr = shift;
my $padl = int (($LINE_LENGTH - length $instr)/2);
my $padr = ($LINE_LENGTH - (length $instr) - $padl);
return (" " x $padl.$instr." " x $padr);
}
Awesome hack. I noticed that the words are not always perfectly centered and it's because if the free space on a line is an odd number, half of it is something-and-a-half and the half never gets accounted for. I made a common function to add padding to all lines. See below.
sub pad
{
my $instr = shift;
my $padl = int (($LINE_LENGTH - length $instr)/2);
my $padr = ($LINE_LENGTH - (length $instr) - $padl);
return (" " x $padl.$instr." " x $padr);
}
And even though there was an error the weather did show up on the printer.
I am trying to convert this hack on VB6, but instead of changing display it prints the lines. I wonder if i am missing some key element?
Usch, my own fault (who elses?). Now my vb6 version works fine. If anyone knows that this is possible to Canon also, i would like to know. Thank you for great hack!
Save me from my misery... does anyone have the spacing figured out for an HP 9000 printer?
I have modified parts of this for the HP 4050 I wont bogart the code.. here it is! Nice Work!
my $wx;
$wx = "LAX:"; # This can be edited to localize it.
# Keep it the same length and center
# the text in the quotes with spaces.
# my $temp = $m->TEMP_F."F/".$m->TEMP_C."C";
my $temp = $m->TEMP_F."F";
my $pad = (20 - length $temp)/2;
$wx .= "" x $pad.$temp."" x $pad;
my $vis = $m->VISIBILITY;
$vis =~ /(\d+)/;
my $atmos = " v$1mi.";
$pad = (20 - length $atmos)/2;
$wx .= "" x $pad.$atmos."" x $pad;
my $wspd = $m->WIND_MPH;
my $wind = "Wind:$wspd mph";
$pad = (20 - length $wind)/2;
$wx .= "" x $pad.$wind."" x $pad;
return $wx;
Post a Comment
Links to this post:
Create a Link
<< Home