summaryrefslogtreecommitdiffstats
path: root/piano-alarm/mt300-v2/usr
diff options
context:
space:
mode:
Diffstat (limited to 'piano-alarm/mt300-v2/usr')
-rwxr-xr-xpiano-alarm/mt300-v2/usr/bin/piano_alarm55
-rwxr-xr-xpiano-alarm/mt300-v2/usr/bin/sensor.pl93
2 files changed, 148 insertions, 0 deletions
diff --git a/piano-alarm/mt300-v2/usr/bin/piano_alarm b/piano-alarm/mt300-v2/usr/bin/piano_alarm
new file mode 100755
index 0000000..de5677c
--- /dev/null
+++ b/piano-alarm/mt300-v2/usr/bin/piano_alarm
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+message()
+{
+STATE="$1"
+echo -e "Subject: 41hpa piano alarm: ${STATE} \n\nPiano alarm at 41hpa says ${STATE}.\n" | /usr/sbin/sendmail -f "Piano Alarm <piano-alarm@ourano.org>" monitoring@madingley.org
+}
+
+TL=17000
+TH=22000
+
+HL=450
+HH=700
+
+T=`sensor.pl -t -i`
+H=`sensor.pl -h -i`
+
+exit 0
+
+BAD=0
+
+if [ -z "$T" ]; then
+ BAD=1
+fi
+if [ -z "$H" ]; then
+ BAD=1
+fi
+
+if [ "$T" -lt "$TL" ]; then
+ BAD=1
+fi
+if [ "$T" -gt "$TH" ]; then
+ BAD=1
+fi
+
+if [ "$H" -lt "$HL" ]; then
+ BAD=1
+fi
+
+if [ "$H" -gt "$HH" ]; then
+ BAD=1
+fi
+
+if [ "$1" == "test" ]; then
+ BAD=1
+fi
+
+if [ "$BAD" -eq 1 ]; then
+ message "T=$T (should be $TL-$TH) H=$H (should be $HL-$HH)"
+fi
+
+echo "piano_alarm T=$T H=$H"
+logger "piano_alarm T=$T H=$H"
+
+
diff --git a/piano-alarm/mt300-v2/usr/bin/sensor.pl b/piano-alarm/mt300-v2/usr/bin/sensor.pl
new file mode 100755
index 0000000..9a5501d
--- /dev/null
+++ b/piano-alarm/mt300-v2/usr/bin/sensor.pl
@@ -0,0 +1,93 @@
+#!/usr/bin/env perl
+
+use strict;
+
+use Device::SerialPort;
+
+sub get_line($) {
+ my $port = shift;
+
+ my $ret = "";
+
+ while (1) {
+ my ( $count, $byte ) = $port->read(1);
+
+ if ( $count > 0 ) {
+ $ret .= $byte;
+ return $ret if $byte eq "\n";
+ }
+ else {
+ return $ret;
+ }
+ }
+}
+
+sub display($$$$$$) {
+ my ( $t, $h, $show_t, $show_h, $int, $mrtg ) = @_;
+
+ if ( $int or $mrtg ) {
+ $t = int( $t * 100 );
+ $h = int( $h * 10 );
+ }
+
+ if ($mrtg) {
+ if ($show_t) {
+ print "$t\n";
+ print "0\n";
+ print "long time\n";
+ print "temperature\n";
+ }
+
+ if ($show_h) {
+ print "$t\n";
+ print "0\n";
+ print "long time\n";
+ print "humidity\n";
+ }
+ }
+ else {
+ print "$t\n" if $show_t;
+ print "$h\n" if $show_h;
+ }
+}
+
+my $keypad_port = "/dev/ttyS1";
+my $keypad = new Device::SerialPort($keypad_port)
+ || die "can't open $keypad_port\n";
+
+$keypad->baudrate(115200);
+$keypad->parity("none");
+$keypad->databits(8);
+$keypad->stopbits(1);
+$keypad->stty_icanon(0);
+
+$keypad->read_char_time(0);
+$keypad->read_const_time(1000);
+
+my $mrtg = 0;
+my $temp = 0;
+my $humid = 0;
+my $int = 0;
+
+for my $opt (@ARGV) {
+ $mrtg = 1 if $opt eq '-m';
+ $temp = 1 if $opt eq '-t';
+ $humid = 1 if $opt eq '-h';
+ $int = 1 if $opt eq '-i';
+}
+
+for ( my $tries = 0 ; $tries < 4 ; ++$tries ) {
+ my $line = get_line($keypad);
+
+ chomp $line;
+ chomp $line;
+
+ if ( $line =~ /\$SNTHD,([-.0-9]+),([-.0-9]+)/ ) {
+
+ display( $1, $2, $temp, $humid, $int, $mrtg );
+ exit 0;
+ }
+}
+
+exit 1;
+