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_alarm50
-rwxr-xr-xpiano-alarm/mt300-v2/usr/bin/sensor.pl74
l---------piano-alarm/mt300-v2/usr/sbin/sendmail1
3 files changed, 117 insertions, 8 deletions
diff --git a/piano-alarm/mt300-v2/usr/bin/piano_alarm b/piano-alarm/mt300-v2/usr/bin/piano_alarm
index de5677c..b82f147 100755
--- a/piano-alarm/mt300-v2/usr/bin/piano_alarm
+++ b/piano-alarm/mt300-v2/usr/bin/piano_alarm
@@ -9,47 +9,85 @@ echo -e "Subject: 41hpa piano alarm: ${STATE} \n\nPiano alarm at 41hpa says ${ST
TL=17000
TH=22000
-HL=450
+HL=400
HH=700
T=`sensor.pl -t -i`
H=`sensor.pl -h -i`
-
-exit 0
+TANK="$(mosquitto_sub -h 10.32.136.1 -p 1883 -t stat/music_room_humidifier/var3 -W 1 -C 1 )"
BAD=0
+M=""
+
if [ -z "$T" ]; then
+ if [ ! -z "$M" ]; then
+ M="${M}, "
+ fi
+ M="${M}failed to read temperature"
BAD=1
fi
+
if [ -z "$H" ]; then
+ if [ ! -z "$M" ]; then
+ M="${M}, "
+ fi
+ M="${M}failed to read humidity"
BAD=1
fi
if [ "$T" -lt "$TL" ]; then
+ if [ ! -z "$M" ]; then
+ M="${M}, "
+ fi
+ M="${M}temperature too low $T<$TL"
BAD=1
fi
if [ "$T" -gt "$TH" ]; then
+ if [ ! -z "$M" ]; then
+ M="${M}, "
+ fi
+ M="${M}temperature too high $T>$TH"
BAD=1
fi
if [ "$H" -lt "$HL" ]; then
+ if [ ! -z "$M" ]; then
+ M="${M}, "
+ fi
+ M="${M}air too dry $H<$HL"
BAD=1
fi
if [ "$H" -gt "$HH" ]; then
+ if [ ! -z "$M" ]; then
+ M="${M}, "
+ fi
+ M="${M}air too wet $H>$HH"
BAD=1
fi
if [ "$1" == "test" ]; then
+ if [ ! -z "$M" ]; then
+ M="${M}, "
+ fi
+ M="${M}test"
+ BAD=1
+fi
+
+if [ $TANK -eq 0 ]; then
+ if [ ! -z "$M" ]; then
+ M="${M}, "
+ fi
+ M="${M}humidifier tank is empty"
BAD=1
fi
if [ "$BAD" -eq 1 ]; then
- message "T=$T (should be $TL-$TH) H=$H (should be $HL-$HH)"
+ message "$M"
fi
-echo "piano_alarm T=$T H=$H"
-logger "piano_alarm T=$T H=$H"
+echo "piano_alarm T=$T H=$H TANK=$TANK M=$M"
+logger "piano_alarm T=$T H=$H TANK=$TANK M=$M"
diff --git a/piano-alarm/mt300-v2/usr/bin/sensor.pl b/piano-alarm/mt300-v2/usr/bin/sensor.pl
index 9a5501d..6004db8 100755
--- a/piano-alarm/mt300-v2/usr/bin/sensor.pl
+++ b/piano-alarm/mt300-v2/usr/bin/sensor.pl
@@ -22,11 +22,78 @@ sub get_line($) {
}
}
+
+#from W. Wagner and A. Pruß:" The IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use ", Journal of Physical and Chemical Reference Data, June 2002 ,Volume 31, Issue 2, pp. 387535
+sub pws($) {
+ my $t = shift;
+ my $tc = 647.096; # critical T in K
+ my $pc = 22064000; # critical P in Pa;
+ my @c = (
+ -7.85951783, 1.84408259, -11.7866497, 22.6807411,
+ -15.9618719, 1.80122502
+ );
+
+ $t += 273.15; #into K
+
+ my $v = 1. - ( $t / $tc );
+
+ my $pn = $c[0] * $v;
+ $pn += $c[1] * ( $v**1.5 );
+ $pn += $c[2] * ( $v**3 );
+ $pn += $c[3] * ( $v**3.5 );
+ $pn += $c[4] * ( $v**4 );
+ $pn += $c[5] * ( $v**7.5 );
+
+ $pn *= $tc / $t;
+
+ return $pc * exp($pn);
+}
+
+sub rh_to_pw($$) {
+ my ( $t, $h ) = @_;
+
+ return pws($t) * ( $h / 100. );
+}
+
+sub pw_to_rh($$) {
+ my ( $t, $pw ) = @_;
+
+ return ( $pw / pws($t) ) * 100.;
+}
+
+sub rh_to_ah($$) {
+ my ( $t, $h ) = @_;
+ my $c = 0.00216679; #kg K /J
+
+ return $c * rh_to_pw( $t, $h ) / ( $t + 273.15 );
+}
+
+sub ah_to_rh($$) {
+ my ( $t, $ah ) = @_;
+ my $c = 0.00216679; #kg K /J
+
+ return pw_to_rh( $t, $ah * ( $t + 273.15 ) / $c );
+}
+
+sub fixup($$) {
+ my ( $t, $h ) = @_;
+
+ my $ah = rh_to_ah( $t, $h );
+
+ my $ct = $t - 1.15;
+
+ my $ch = ah_to_rh( $ct, $ah );
+
+# print "($t,$h) => ($ct,$ch)\n";
+
+ return ( $ct, $ch );
+}
+
sub display($$$$$$) {
my ( $t, $h, $show_t, $show_h, $int, $mrtg ) = @_;
if ( $int or $mrtg ) {
- $t = int( $t * 100 );
+ $t = int( $t * 1000 );
$h = int( $h * 10 );
}
@@ -84,9 +151,12 @@ for ( my $tries = 0 ; $tries < 4 ; ++$tries ) {
if ( $line =~ /\$SNTHD,([-.0-9]+),([-.0-9]+)/ ) {
- display( $1, $2, $temp, $humid, $int, $mrtg );
+ my ( $t, $h ) = fixup( $1, $2 );
+
+ display( $t, $h, $temp, $humid, $int, $mrtg );
exit 0;
}
+ sleep(int(rand(4)));
}
exit 1;
diff --git a/piano-alarm/mt300-v2/usr/sbin/sendmail b/piano-alarm/mt300-v2/usr/sbin/sendmail
new file mode 120000
index 0000000..071af7e
--- /dev/null
+++ b/piano-alarm/mt300-v2/usr/sbin/sendmail
@@ -0,0 +1 @@
+../bin/msmtp \ No newline at end of file