summaryrefslogtreecommitdiffstats
path: root/piano-alarm/mt300-v2/usr/bin/sensor.pl
diff options
context:
space:
mode:
Diffstat (limited to 'piano-alarm/mt300-v2/usr/bin/sensor.pl')
-rwxr-xr-xpiano-alarm/mt300-v2/usr/bin/sensor.pl74
1 files changed, 72 insertions, 2 deletions
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;