Perl Weather Script for HP Printers

I saw a post on Digg today about changing the Ready message on the screen of your HP Printers. So I took a look at it and modified it so that it will read the XML output of the Google weather service. Just change the IP address to that of your HP Printer and then set it up as a scheduled task. Then change the Google URL to your location.

http://www.google.com/ig/api?weather=      03051     &hl=en

If you ever want to know how cold it is outside, take a look at your printer.

 

#!/usr/bin/perl

  # $Id: hpsetdisp.pl 11 2006-03-22 01:21:03Z yaakov $

  # hpsetdisp.pl 
  # Connects to a JetDirect equipped HP printer and uses
  # HP's control language to set the ready message on the
  # LCD display.  Takes an IP address and message on the
  # command line. My favorite message is "INSERT COIN".
  # Keep in mind the limitations of the display when composing
  # your clever verbiage.
  #
  # THIS PROGRAM IS PROVIDED WITH NO WARRANTY OF ANY KIND EXPRESSED OR IMPLIED
  # THE AUTHOR CANNOT BE RESPONSIBLE FOR THE EFFECTS OF THIS PROGRAM
  # IF YOU ARE UNCERTAIN ABOUT THE ADVISABILITY OF USING IT, DO NOT!
  #
  # Yaakov (http://kovaya.com/ )
  #
  # Modified by Garrett Hoofman
  # 10/18/2007
  # http://www.visionsofafar.com

use strict;
use warnings;
use XML::DOM;

 

 

 

my $file = 'http://www.google.com/ig/api?weather=03051&hl=en';

my $peeraddr = "192.168.83.4";

 

 


my $rdymsg = "Ready";

my $parser = XML::DOM::Parser->new();
my $doc = $parser->parsefile($file);

foreach my $species ($doc->getElementsByTagName('current_conditions')){
  $rdymsg = $species->getElementsByTagName('temp_f')->item(0)
            ->getAttribute('data') . " Degrees Out      " . $species->getElementsByTagName('condition')->item(0)
            ->getAttribute('data');
  print "\n";
}

chomp $peeraddr;

use IO::Socket;
my $socket = IO::Socket::INET->new(
    PeerAddr  => $peeraddr,
    PeerPort  => "9100",
    Proto     => "tcp",
    Type      => SOCK_STREAM
    ) or die "Could not create socket: $!";

my $data = <<EOJ
\e%-12345X\@PJL JOB
\@PJL RDYMSG DISPLAY="$rdymsg"
\@PJL EOJ
\e%-12345X
EOJ
;

print $socket $data;

Print | posted on Thursday, October 18, 2007 3:16 PM

Comments on this post

# re: Perl Weather Script for HP Printers

Requesting Gravatar...
I'd like to try the script but I keep receiving the error "Can't find string terminator EOJ anywhere before EOF" when I run it. Do you have any guidance on how to get past it?
Left by Hal on Dec 09, 2007 1:40 PM

# re: Perl Weather Script for HP Printers

Requesting Gravatar...
The EOJ must start in the first column and be the only thing on the line. There is a space in the listing.

--Yaakov
Left by Yaakov on Jun 12, 2008 3:22 PM

# re: Perl Weather Script for HP Printers

Requesting Gravatar...
I cant get this to work for the life of me. It just errors.. Can't locate XML/DOM.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) I have attempted to install the XML::DOM plugin through the perl shell and it looks like it tries to install but ends with a make install error. I also installed the latest version of perl. Some guidance would be helpful.
Left by SixPack on Oct 07, 2008 10:45 AM

# This website owner claims he discovered great affiliate websites

Requesting Gravatar...
So previous month I was thinking about starting my own affiliate marketing business and to obtain any affiliate websites I just don't know if it is better to build one myself or obtain any already turnkey affiliate marketing websites. I just discovered website
website affiliate and here was two reviews about these sites but I still haven't made decision what to do. Maybe here some people who can give some opinion about websites reviewed at that site?
http://www.home-businessreviews.com/Turnkey-Affiliate-Websites.html
Left by Utinvaria on Oct 26, 2009 5:53 PM

# Turnkey Affiliate websites is it worth to purchase them

Requesting Gravatar...
Maybe memebers know what are good benefits of buying affiliate websites? previous month I'm considering to purchase one? Can anyone have opinion of some good website to read any more reviews or opinions which site can produce large income? I found this site
affiliate websites - owner told that he had very good success using these affiliate marketing websites. He wrote that he earns thousands of cash every month with these sites. Waiting for any reply.
that is site I 'm talking
http://www.home-businessreviews.com/Turnkey-Affiliate-Websites.html
Left by affiliate websites on Nov 05, 2009 5:53 PM

Your comment:

 (will show your gravatar)