#!/usr/bin/perl -w # Reads data from a number of XRF aProtocol devices via serial port. # # Andrew Lindsay http://blog.thiseldo.co.uk # use strict; use Device::SerialPort qw( :PARAM :STAT 0.07 ); use URI::Escape; # Alter these values to suit your configuration # Serial port CC128 connected to my $PORT = "/dev/ttyUSB0"; # supertweet.net values - basic auth proxy for twitter. my $twitterUser = "xxxxxxxxxxxxxxx"; my $twitterPass = "xxxxxxxxxx"; # End of configuration # Setup the serial port. my $ob = Device::SerialPort->new($PORT); $ob->baudrate(9600); $ob->write_settings; print "Reading XRF aProtocol datastream on $PORT\n"; open(SERIAL, "+>$PORT"); my $haveTweeted = "N"; while (my $line = ) { print "$line\n"; if ($line =~ m!M1TRAPOK! ) { print "Trap initialised\n"; $haveTweeted = "N"; } if ($line =~ m!M1TRAPTRIG! ) { # process Mouse caught print "$line\n"; # Tweet mouse caught if( "$haveTweeted" eq "N" ) { $haveTweeted = "Y"; print "Tweet\n"; my $tweetstatus = uri_escape( "Trap M1 triggered - Check for mouse" ); system( "curl -s -u $twitterUser:$twitterPass -d 'status =$tweetstatus' http://api.supertweet.net/1/statuses/update.xml"); } } }