Created
May 16, 2017 10:29
-
-
Save Funi1234/987b92465208910102f9325591ab5188 to your computer and use it in GitHub Desktop.
HKC Perl
This file contains hidden or 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 -w | |
use strict; | |
use Device::SerialPort qw( :PARAM :STAT 0.07 ); | |
use MIME::Lite; | |
my $to = '[email protected]'; | |
my $cc; | |
my $from = '[email protected]'; | |
my $subject; | |
my $message; | |
my$ msg; | |
my $PORT = "/dev/ttyUSB0"; | |
my $line; | |
my $ob = Device::SerialPort->new($PORT) || die "Can't open $PORT: $!\n"; | |
$ob->baudrate(2400); | |
$ob->parity("none"); | |
$ob->databits(8); | |
$ob->stopbits(1); | |
$ob->write_settings; | |
open(SERIAL, "+>$PORT"); | |
while (my $line = <SERIAL>) { | |
if ($line =~ m/Alarm/) { | |
print "Got Alarm!!\n"; | |
$subject = '****Alarm****'; | |
} | |
elsif ($line =~ m/Full set/) { | |
print "Got Full Set!!\n"; | |
$subject = 'System Fully Armed'; | |
} | |
elsif ($line =~ m/Unset/) { | |
print "Got Unset!!\n"; | |
$subject = 'System Disarmed'; | |
} | |
elsif ($line =~ m/Night Arm/) { | |
print "Got Night Arm!!\n"; | |
$subject = 'System Night Armed'; | |
} | |
elsif ($line =~ m/Airing Arm/) { | |
print "Got Airing Arm\n"; | |
$subject = 'System Airing Armed'; | |
} | |
elsif ($line =~ m/Tamper/) { | |
print "Got Tamper\n"; | |
$subject = '****Alarm-Tamper****'; | |
} | |
elsif ($line =~ m/Mains/) { | |
print "Got Mains Fault\n"; | |
$subject = 'Mains Fault'; | |
} | |
elsif ($line =~ m/Power/) { | |
print "Got Power Failure"; | |
$subject = 'System Power Failure'; | |
} | |
elsif ($line =~ m/Exit Fault/) { | |
print "Got Exit Fault\n"; | |
$subject = 'Exit Fault'; | |
} | |
elsif ($line =~ m/User Inhibit/) { | |
print "Got Inhibited Zone\n"; | |
$subject = 'Zone Inhibited'; | |
} | |
else { | |
print "Got an undefined event!\n"; | |
$subject = 'Undefined event'; | |
} | |
$message=$line; | |
chomp $message; | |
$msg = MIME::Lite->new( | |
From => $from, | |
To => $to, | |
#Cc => $cc, | |
Subject => $subject, | |
Data => $message | |
); | |
$msg->send('smtp', "your isps email server" ); | |
print "Email Sent Successfully\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment