Created
November 11, 2011 17:33
Skeleton Perl script to program sensor attached to XBee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use Xbee::API; | |
use Data::Dumper; | |
my $port = "/dev/ttyUSB0"; | |
my $end_device = "0013a20040769646"; | |
my $remaddr = pack( "H*", $end_device ); | |
my $devaddr = pack( "H4", "fffe" ); | |
my $sp = pack( "n", 2400 ); # 24s | |
my $sn = pack( "n", 4 ); | |
my $st = pack( "n", 5000 ); # 5s | |
my $ir = pack( "n", 5100 ); # > $st -> 1 sample | |
my $xbee = Xbee::API->new( { port => $port, debug => 0, speed => 9600 } ); | |
sub remote_send_wait | |
{ | |
($cmd, $data) = @_; | |
$id = $xbee->at_command_remote( $remaddr, $devaddr, $cmd, $data ); | |
$frame = $xbee->read_api; | |
if (defined $frame && $frame->{status} == 0 && $frame->{id} == $id ) { | |
print "received reply to $cmd OK\n"; | |
} else { | |
print "$cmd failed!\n"; | |
print Dumper($frame); | |
} | |
} | |
remote_send_wait( "SP", $sp ); # sleep period (10mS units) | |
remote_send_wait( "SN", $sn ); # sleep multiplier | |
remote_send_wait( "ST", $st ); # time before sleep (1mS units) | |
remote_send_wait( "IR", $ir ); # I/O read | |
remote_send_wait( "SO", pack( "C", "06") ); # sleep options: extended sleep | |
remote_send_wait( "SM", pack( "C", "04") ); # sleep mode periodic | |
start: while (1) { | |
my $frame = $xbee->read_api; | |
next start if !defined $frame; | |
print Dumper($frame); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment