From: Jan Michel Date: Sun, 9 Aug 2015 21:56:13 +0000 (+0200) Subject: adding web interface for temperature sensors X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=2e987e0bad93de2e729d4a3f6feebc1fa9ab9012;p=labtools.git adding web interface for temperature sensors --- diff --git a/sensors/config/default.conf b/sensors/config/default.conf new file mode 100644 index 0000000..6ce2ad7 --- /dev/null +++ b/sensors/config/default.conf @@ -0,0 +1,36 @@ +#Board Sensor Y X Name +0 0 1 0 +0 1 1 5 +0 2 1 10 +0 3 1 15 +0 4 13 15 +0 5 9 10 +0 6 13 5 +0 7 9 0 + +1 0 5 10 +1 1 13 0 +1 2 9 5 +1 3 5 15 +1 4 9 15 +1 5 5 0 +1 6 13 10 +1 7 5 5 + +2 0 1 25 CoolIn +2 1 4 25 CoolOut +2 2 25 20 +2 3 25 21 +2 4 25 22 +2 5 25 23 +2 6 25 24 +2 7 25 25 + +3 0 29 18 +3 1 29 19 +3 2 29 20 +3 3 29 21 +3 4 29 22 +3 5 29 23 +3 6 29 24 +3 7 29 25 diff --git a/sensors/data/pt100.log b/sensors/data/pt100.log new file mode 100644 index 0000000..e5c8fe8 --- /dev/null +++ b/sensors/data/pt100.log @@ -0,0 +1,18 @@ +AT001ffbb4 +AT01100a28 +AT021021fc +AT03102af8 +AT04102ee0 +AT051028a0 +AT06102580 +AT07101a2c +AT10102774 +AT11102580 +AT121021fc +AT13102af8 +AT14102ee0 +AT151ffeff +AT16102ee0 +AT17000000 +AT20102580 +AT21101a2c diff --git a/sensors/index.htm b/sensors/index.htm new file mode 100644 index 0000000..451caa8 --- /dev/null +++ b/sensors/index.htm @@ -0,0 +1,107 @@ + + + + Temperature Visualizer + + + + + + + + +
+
+ + + + diff --git a/sensors/style.css b/sensors/style.css new file mode 100644 index 0000000..42a6717 --- /dev/null +++ b/sensors/style.css @@ -0,0 +1,95 @@ +body { + font-family:"Trebuchet MS"; + margin:0; + height:100%; + width:100%; +} + +#header { + width:100%; + height:90px; + background:#eee; + border-bottom:1px solid #aaa; + position:relative; + } + +h1{ + font-size:25px; + color:#aaa; + margin:0 0 0 10px; + padding:0; + } + +#info { + position:absolute; + bottom:0; + right:20px; + text-align:right; +} + +#container { + margin:20px; + position:relative; + } + + +.sensor{ + background:red; + position:absolute; + width:80px; + height:40px; + border-radius:0 15px 0 0; + border:1px solid #aaa; + margin:auto; + cursor:default; + font-family:monospace; + box-model:border-box; + box-shadow:3px 3px 2px 2px #ddd; + } + +.value { + width:100%; + height:100%; + margin-left:5px; + margin-top:2px; + font-size:20px; + user-select: none; + -moz-user-select: none; +} + +.sid { + padding:2px; + font-family:monospace; + position:absolute; + right:0; + bottom:-2px; + font-size:10px; + user-select: none; + -moz-user-select: none; +} + +.name { + padding:2px; + font-family:monospace; + position:absolute; + bottom:-2px; + font-size:10px; + width:80px; + height:12px; + user-select: none; + -moz-user-select: none; +} + +.scale { + position:absolute; + bottom:20px; + } + +table.scale { + display:inline-block; + border-collapse:collapse; + } + +.scale td { + min-width:12px; +} diff --git a/sensors/update.pl b/sensors/update.pl new file mode 100755 index 0000000..eb6812a --- /dev/null +++ b/sensors/update.pl @@ -0,0 +1,118 @@ +#!/usr/bin/perl +print "Content-Type: text/html; charset=utf-8\r\n\r\n"; + +use warnings; +use strict; +use CGI::Carp qw(warningsToBrowser fatalsToBrowser); +use utf8; +use POSIX; +use List::Util qw(min max); + +my $min = 1000; +my $max = -1000; + +sub defineScale { + my $aref = shift @_; + $min = min(@{$aref}); + $max = max(@{$aref}); + + $min = floor($min/5)*5; + $max = ceil($max/5)*5; + + } + + +sub findcolor { + my ($v,$min,$max) = @_; + my ($r,$g,$b); + $v = 0 unless defined $v; + + my $step = (($max-$min)/1000.); + + + if ($v == 0) { + $r = 220; + $g = 220; + $b = 220; + } else { + $v -= $min; + $v = $v/$step if $step; + if ($v<240) { $r = 255-$v/240*255;} + elsif ($v<333) { $r = 0;} + elsif ($v<666) { $r = ($v-333)/333.*255.;} + elsif ($v<900) { $r = 255;} + else { $r = 255 - ($v-900);} + + if ($v<200) { $g = 0;} + elsif ($v<430) { $g = ($v-200)/230.*255.;} + elsif ($v<730) { $g = 255;} + elsif ($v<920) { $g = 255-($v-730)/190.*255.;} + else { $g = 0;} + + if ($v<160) { $b = 200+$v/160.*55.;} + elsif ($v<333) { $b = 255;} + elsif ($v<666) { $b = 255-($v-333)/333.*255.;} + else { $b = 0;} + } + + my $ret = sprintf("#%02x%02x%02x",$r%256,$g%256,$b%256); + + return $ret; +} + + +sub DrawScale { + my ($min,$max,$steps) = @_; + my $str; + return "" if $max == $min; + $str .= ""; + $str .= sprintf("
",findcolor(0,0,$steps,0)); + return $str.="
" if $max == $min; + $str .= sprintf("%#2.3G",$min); + for (my $i = 1;$i<$steps;$i++) { + # my $j = ($max-$min)/$steps*$i; + $str .= sprintf("",findcolor($i,0,$steps,0),($max-$min)/$steps*$i+$min); + } + $str .= sprintf("%#2.3G",$max); + $str .= "\n"; + return $str; +} + +my $values; +my $tfile = "tail -n40 data/pt100.log"; +open(my $tdata, '-|', $tfile) or die "Could not open '$tfile' $!\n"; +while (my $line = <$tdata>) { + #AT051028a0 + if($line =~ /^AT([0-9])([0-9])([0-1])((\w){5})/){ + next if $2 >= 8; + my $v = hex($4); + $v -= 0x100000 if $v >= 0x80000; + $values->[$1*8+$2] = $v/1000.; + $values->[$1*8+$2] = undef unless $3; + } + } + +defineScale($values); + +my $cfile = "config/default.conf"; +open(my $cdata, '<', $cfile) or die "Could not open '$cfile' $!\n"; +while (my $line = <$cdata>) { + $line =~ s/#.*//; + my @f = split(" " , $line); + if(defined $f[3]) { + $f[4] = $f[4] || ''; + my $val = '--.--'; + $val = sprintf('%02.2f',$values->[$f[0]*8+$f[1]]) if defined $values->[$f[0]*8+$f[1]]; + print " +
[$f[0]*8+$f[1]],$min,$max)."\"> +
$val
+
$f[0]/$f[1]
+
$f[4]
+
+ "; + } + + } + +print '
'.DrawScale($min,$max,50).'
'; + \ No newline at end of file diff --git a/sensors/writeconfig.pl b/sensors/writeconfig.pl new file mode 100755 index 0000000..b99e9d4 --- /dev/null +++ b/sensors/writeconfig.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl +print "Content-Type: text/html; charset=utf-8\r\n\r\n"; + +use warnings; +use strict; +use CGI::Carp qw(warningsToBrowser fatalsToBrowser); +use utf8; +use Data::Dumper; + + +my $str = $ENV{'QUERY_STRING'}; +my @new = split(',', $str); +$str =~ s/,/\t\t\t\t/g; + +my $out = ""; + +my $cfile = "config/default.conf"; +open(my $cdata, '<', $cfile) or die "Could not open '$cfile' $!\n"; +while (my $line = <$cdata>) { + chomp $line; + if($line =~ /^#/) { + $out .= $line."\n"; + next; + } + + my @f = split(" " , $line); + if(defined $f[3] && $f[0] eq $new[0] && $f[1] eq $new[1] ) { + $out .= $str."\n"; + } + else { + $out .= $line."\n"; + } + } +close($cdata); + +open($cdata, '>', $cfile) or die "Could not open '$cfile' $!\n"; +print $cdata $out; +close($cdata); + \ No newline at end of file