#!/usr/bin/perl # This script generates the trend graphs for the pressure reading. It takes # parameters "unit" (naming the unit) and "length" with values 0...4, # for day/week/month/quarter/year as arguments, passed by via GET method. # Directories where the log files reside in #$logdir="/home/chris/BTUmetering/log"; #$gnudir="/home/chris/BTUmetering/gnuplot"; $logdir="MAINPROGROOT/log"; $gnudir="MAINPROGROOT/gnuplot"; # Image directory: # $imgdir="/srv/www/htdocs/img2"; $imgdir="HTDOCROOT/img2"; @allowedcores = ("AHU2"); # Following http://www.tutorialspoint.com/perl/perl_cgi.htm, we extract the # parameters sent via get: local ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; } # sanitize input $buffer =~ s/[^\w =&+]//g; # Split information into name/value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $FORM{$name} = $value; } # Extract the interesting ones $core = $FORM{unit}; $timespan = $FORM{length}; # Generate page header print "content-type: text/html\n\n"; print "
Sorry, logging for the requested unit is not (yet) implemented.
\n"; } else { # test if we have proper value 0...3 for length if ($timespan !~ /[0123]/) { # by default, take a week $timespan=1; } # For debugging # $timespan=1; # $core="AHU2"; # Prepare flexible arguments for gnuplot for different sizes @datapoints = ( 1500, 10800, 46000, 120000); @samplingdensity = (1, 10, 30, 120); @outputformat = ("%m/%d\\n%H:%M", "%a\\n%m/%d\\n%H:%M", "%m/%d", "%d.%b"); $imagename = $core."_p_".$datapoints[$timespan].".png"; # compose parameter set for gnuplot $parset="core=\"$core\"; num=$datapoints[$timespan]; evr=$samplingdensity[$timespan]; ofmt=\"$outputformat[$timespan]\"; outfilename=\"$imagename\"; logdir=\"$logdir\"; imgdir=\"$imgdir\" \n"; # generate image open GNUPLOT, "| gnuplot - $gnudir/pressure.gnu >/dev/null"; print GNUPLOT $parset; close GNUPLOT; # Generate web page print "Show other time span: day | week | month | quarter
Show other unit: AHU2
"; } # Link to instantaneous reading print "Show instantaneous sensor values
"; # Link to main page of this server print "Back to main page.
"; # Finish html page print "\n\n";