Order Tray | Contact Us | Home | SIG Lists

E-mail notification (was Re: [aprssig] Perl cell phone and Pager)

Arne Stahre sm6vyf at gatugarden.com
Wed Feb 1 11:08:12 UTC 2006


Tyson S. wrote:
> I got excited when I saw the subject line for the first time and
> thought someone had added a feature I have been trying to make. I was
> un-successful in getting PERL-APRS running on my PHP-PERL home server
> the last time I tried. Mostly due to my total lack of programming
> knowledge. But the feature I am looking for is to be able to enter
> various area coordinates similar to the filter on a server and when
> your choice of station enters these areas a message is sent to an email
> address. In my case the email would be my cell phone. The station could
> be specific, a wild card of any SSID or a wildcard of any call sign or
> object that enters your areas of choice. If any one has experience with
> getting this application installed and running I would gladly accept
> any tips or advice you may have. Thanks. N7ZMR, Oregon.

  Well, using the junkbox, I came up with the following. It uses the 
APRS-IS filter and notifies for any packet (except server comments) 
received from the APRS-IS (one mail per packet!).

#!/usr/bin/perl -w
# 1.II.06 SM6VYF/Arne
use Socket;
use Net::SMTP;
use strict;

# For filter selection see:
# http://www.aprs-is.net/javAPRSSrvr/javaprsfilter.htm

our $HOST = 'northwest.aprs2.net';	# APRS-IS (eg.)
our $PORT = '14580';			# Select filtered port!
our $FILTER = 'a/58/10/56/12/';		# Filter (edit as wanted)

our $SENDER = 'user1 at host.domain'; 	# Who's sending this
our $RECIPIENT = 'user2 at host.domain';	# To whom the mail is sent
our $MAILSERVER = 'host.domain';	# SMTP server to connect to

our $TIMEOUT = 10;

sub connect_to_net {
   my ($host, $port) = @_;

   my $in_addr = (gethostbyname($host))[4];
   my $addr = sockaddr_in($port, $in_addr);
   my $proto = getprotobyname('tcp');
   socket(APRSPORT, AF_INET, SOCK_STREAM, $proto) or die "socket:$!";
   connect(APRSPORT, $addr) or die "connect:$!";
}

sub notify {
   my ($packet) = @_;

   my $smtp = Net::SMTP->new($MAILSERVER);
   $smtp->mail($SENDER);
   $smtp->to($RECIPIENT);

   $smtp->data();
   $smtp->datasend("To: $RECIPIENT\n");
   $smtp->datasend("From: $SENDER\n");
   $smtp->datasend("Subject: APRS notification\n");
   $smtp->datasend("\n");
   $smtp->datasend($packet);
   $smtp->dataend();

   $smtp->quit();
}

my $packet;
my $running = 1;

connect_to_net($HOST, $PORT);

select APRSPORT; $| = 1;
print APRSPORT "#filter $FILTER\r";

select STDOUT; $| = 1;		# DEBUG

$SIG{INT} = sub { $running = 0 };

while ($running) {		# perldoc -f alarm
   eval {
     local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
     alarm $TIMEOUT;
     $packet = <APRSPORT>;
     alarm 0;
   };
   if ($@) {
     die unless $@ eq "alarm\n"; # propagate unexpected errors
   } elsif (! $packet) {
     $running = 0;
   } elsif (length $packet ne 0) {
     print $packet;		# DEBUG
     notify($packet) unless ($packet =~ /^#/);  # Don't mail server comments
   }
}

close(APRSPORT);




More information about the aprssig mailing list