#!/usr/bin/perl
#
# Read the temperature logfile and make an entry for the webpage
#
# Sensor #0 is the Window
# Sensor #1 is the inside of the Linux box
#
# Dec 18 21:46:47  Sensor 0 C: 8.81 F: 47.86
# Dec 18 21:46:47  Sensor 1 C: 26.41 F: 79.54
#

print "Content-type: text/html\n\n";

print "The current temperature at the Islet is:<P>\n";
# print "<PRE>\n";


# Run tail -2 /var/log/temperature and parse the output

open( TEMPLOG, "tail -2 /var/log/temperature |") || die "Can't fork: $!";

while( <TEMPLOG> )
{

  # Get the time and date, sensor number, temperature in c and f
  ($month,$day,$time,$d1,$sensor,$d1,$centigrade,$d1,$fahrenheight) = split( " ", $_ );

  if( $sensor eq '0' )
  {
    print "The inside of the window is $fahrenheight degrees F ($centigrade degrees C)<BR>\n";
  }

  if( $sensor eq '1' )
  {
    print "The inside of the Nexus Computing Linux box is a ";

    if( $fahrenheight >= 100.0 )
    {
      print "Blistering";
    }

    if( $fahrenheight > 80.0 )
    {
      print "Balmy";
    }

    if( $fahrenheight > 70.0 )
    {
      print "Comfortable";
    }

    if( $fahrenheight >= 40.0 )
    {
      print "Chilly";
    }

    if( $fahrenheight < 40.0 )
    {
      print "Freezing";
    }

    print " $fahrenheight degrees F ($centigrade degrees C)<BR>\n";
  }
}

close( TEMPLOG );

# print "</PRE>\n";

print "Last updated: $month $day $time<BR>\n";
