January 2002
Beginner
480 pages
13h 15m
English
We’re going to use Perl and the Net::Jabber libraries
to build the script shown in Example 9-6. Perl allows us a comfortable way to interact with an
ActiveX control, through the Win32::OLE module, so let’s have a look at the coffee script as a whole, then we’ll go back and look at the script in detail.
use Net::Jabber qw(Client); use Win32::OLE; use Getopt::Std; use strict; my %opts; getopt('ls', \%opts); use constant SERVER => "merlix.dyndns.org"; use constant PORT => 5222; use constant USERNAME => "coffee"; use constant PASSWORD => "pass"; use constant RESOURCE => "perlscript"; use constant NOCOFFEE => 0; use constant COFFEE => 1; use constant SENSOR => defined($opts{'s'}) ? $opts{'s'} : 0; use constant GRAIN => 1; my $current_status = -1; my @status; $status[NOCOFFEE] = 'xa/Coffeepot is empty'; $status[COFFEE] = '/Coffee is available!'; my $rcx = &setup_RCX(SENSOR); # Either calibrate if no parameters given, or # run with the parameter given as -l, which will # be taken as the pivot between coffee and no coffee &calibrate($rcx) unless defined($opts{'l'}); # Determine initial status (will be either 0 or 1) my $s = &set_status($rcx->Poll(9, SENSOR)); my $jabber = &setup_Jabber(SERVER, PORT, USERNAME, PASSWORD, RESOURCE, $s); # Main loop: check Jabber and RCX while (1) { defined($jabber->Process(GRAIN)) or die "The connection to the Jabber server was broken\n"; my $s = &set_status($rcx->Poll(9, SENSOR)); &set_presence($jabber, ...Read now
Unlock full access