Sensormonitor

id = "temp_vrum"; $sensor[$sensor_count]->name = "Temperatur inne"; $sensor[$sensor_count++]->unit = "C"; $sensor[$sensor_count] = new Sensor(); /*$sensor[$sensor_count]->id = "temp_ute"; $sensor[$sensor_count]->name = "Temperatur ute";*/ $sensor[$sensor_count]->id = "temp_lo"; $sensor[$sensor_count]->name = "Temperatur Lo"; $sensor[$sensor_count++]->unit = "C"; $sensor[$sensor_count] = new Sensor(); $sensor[$sensor_count]->id = "temp_grund"; $sensor[$sensor_count]->name = "Temperatur i grunden"; $sensor[$sensor_count++]->unit = "C"; $sensor[$sensor_count] = new Sensor(); $sensor[$sensor_count]->id = "fukt_grund"; $sensor[$sensor_count]->name = "Fukt i grunden (relativ)"; $sensor[$sensor_count++]->unit = "RF"; /* $sensor[$sensor_count]->id = "dagg_grund"; */ /* $sensor[$sensor_count]->name = "Fukt i grunden (daggpunkt)"; */ /* $sensor[$sensor_count++]->unit = "C"; */ /* $thermometer_count = 0; */ /* $thermometer[$thermometer_count++] = "temp_vrum"; */ /* $thermometer[$thermometer_count++] = "temp_ute"; */ /* $thermometer[$thermometer_count++] = "temp_grund"; */ /* $hygrometer_count = 0; */ /* $hygrometer[$hygrometer_count++] = "fukt_grund"; */ // Fill in default arguments: $time_mode = $_POST["time_mode"]; if ($time_mode == '') { $time_mode = "latest"; } $time_scale = $_POST["time_scale"]; if ($time_scale == '') { $time_scale = "day"; } $unit = $_POST["unit"]; if ($unit == '') { $unit = "c"; } $image_type = $_POST["image_type"]; if ($image_type == '') { $image_type = "png"; } $active_maxmin = $_POST["active_maxmin"]; if (!is_array($active_maxmin)) { $active_maxmin = array(); } $active_sensors = $_POST["active_sensors"]; if (!is_array($active_sensors)) { if (count($active_maxmin) < 1) $active_sensors = array("temp_vrum"); else $active_sensors = array(); } $every = 1; #$x_format = "'%d %b %Y'"; $x_format = "'%d %b %Y'"; #$x2_format = "''"; $x2_format = "'%H:%M'"; if ($time_mode == "all") { $x_range_start = ""; $x_range_end = ""; $every = 100; } else if ($time_mode == "latest") { $x_range_end = ""; $x_range_start_day = $x_range_end_day = date("d"); if ($time_scale == "day") { $x_range_start_day -= 1; $x_format = "'%H:%M'"; } if ($time_scale == "week") { $x_range_start_day -= 7; $every = 4; $x_format = "'%d %b'"; $x2_format = "'%a'"; $offset = "offset first 43200,0"; } $x_range_start_month = $x_range_end_month = date("m"); if ($time_scale == "month") { $x_range_start_month -= 1; $every = 12; $x_format = "'%d %b'"; } $x_range_start_year = $x_range_end_year = date("Y"); if ($time_scale == "year") { $x_range_start_year -= 1; $every = 48; $x_format = "'%d %b %Y'"; } $x_range_start_hour = $x_range_end_hour = date("H"); if ($time_scale == "hour") { $x_range_start_hour -= 1; $every = 1; $x_format = "'%H:%M'"; } $x_range_start_minute = $x_range_end_minute = date("i"); if ($x_range_start_hour < 0) { $x_range_start_hour += 23; $x_range_start_day -= 1; } if ($x_range_start_day < 1) { $x_range_start_day += 31; $x_range_start_month -= 1; } if ($x_range_start_month < 1) { $x_range_start_month += 12; $x_range_start_year -= 1; } } else // time_mode == "interval" { $x_range_start_day = $_POST["start_day"]; $x_range_start_month = $_POST["start_month"]; $x_range_start_year = $_POST["start_year"]; $x_range_start_hour = $_POST["start_hour"]; $x_range_start_minute = $_POST["start_minute"]; $x_range_end_day = $_POST["end_day"]; $x_range_end_month = $_POST["end_month"]; $x_range_end_year = $_POST["end_year"]; $x_range_end_hour = $_POST["end_hour"]; $x_range_end_minute = $_POST["end_minute"]; } switch ($x_range_start_month) { case 2: if ($x_range_start_day > 28) $x_range_start_day = 28; break; case 4: case 6: case 9: case 11: if ($x_range_start_day > 30) $x_range_start_day = 30; break; } if ($time_mode != "all") { $x_range_start = sprintf("'%04d%02d%02d %02d:%02d'", $x_range_start_year, $x_range_start_month, $x_range_start_day, $x_range_start_hour, $x_range_start_minute ); $x_range_end = sprintf("'%04d%02d%02d %02d:%02d'", $x_range_end_year, $x_range_end_month, $x_range_end_day, $x_range_end_hour, $x_range_end_minute ); } else { $x_range_start = ""; $x_range_end = ""; } //echo $x_range_start; echo "\n"; $file_name = "./scratch/temp".rand(); if ($image_type == "svg") { $terminal = "svg dynamic size 800,250 enhanced font 'sans-serif,8' rounded dashed"; #fname 'Gill Sans' fsize 9 rounded dashed"; $file_name .= ".svg"; } else { # transparent fill in PNG only works with gnuplot 4.3 and above $terminal = "png truecolor size 750, 250 enhanced font '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf, 10'"; $file_name .= ".png"; } if ($x_range_end == "''") { $title = "$x_range_start -- nu"; } else { $title = "$x_range_start -- $x_range_end"; } $gnuplot_cmd = "set terminal $terminal; set locale 'sv_SE.UTF-8'; set encoding utf8; set xdata time; set x2data time; set timefmt '%Y%m%d %H:%M:%S'; set format x $x_format; set format x2 $x2_format; #set xtics 86400; set xtics autofreq nomirror scale 0 $offset; # rotate by -10 offset graph 0,-0.1; set x2tics autofreq scale 0 $offset; set autoscale xfix ; set autoscale x2fix; set ytics rangelimit; set key outside; set title '$title'; set style data lines; set style line 101 linewidth 0.75 linecolor rgb '#b0b0b0'; set style line 102 linewidth 0.5 linecolor rgb '#dddddd'; set style fill transparent solid 0.25 noborder; set border 2;"; $y1axis = false; $y2axis = false; foreach ($sensor as $i) { if (in_array( $i->id, $active_sensors ) || in_array( $i->id, $active_maxmin ) ) { if (!$y1axis && $i->unit == "C" ) $y1axis = true; if (!$y2axis && $i->unit == "RF" ) $y2axis = true; } } if ($y1axis) { $gnuplot_cmd .= "set ytics autofreq nomirror scale 0; set mytics; set ylabel '^oC' rotate by 0; set grid xtics ytics mxtics mytics linestyle 101, linestyle 102;"; } if ($y2axis) { $gnuplot_cmd .= "set y2tics autofreq out nomirror scale 1; set my2tics scale 1 autofreq; set y2label '%RF' rotate by 0;"; if (!$y1axis) $gnuplot_cmd .= "set grid xtics y2tics mxtics my2tics linestyle 101, linestyle 102;"; } $gnuplot_cmd .= "set output '$file_name';"; if ($_POST["labels"] == "on") { $gnuplot_cmd .= `cat scratch/labels.plot`; } $gnuplot_cmd .= "plot [$x_range_start:$x_range_end] "; foreach ($sensor as $i) #for ($i = 0; $i < $thermometer_count; $i++) { $ls++; # if (in_array( $thermometer[$i], $active_sensors )) if (in_array( $i->id, $active_sensors )) { /* $info_file = @fopen( "data/".$sensor[$i].".info", 'rb' ); */ /* if ($info_file) */ /* { */ /* $sensor_name = trim( fgets( $info_file ) ); */ /* $unit = trim( fgets( $info_file ) ); */ /* fclose($info_file); */ /* } */ /* else */ /* { */ /* $sensor_name = $sensor[$i]; */ /* $unit = "C"; */ /* } */ $gnuplot_cmd .= "'data/$i->id.log' every $every using 1:3 title '$i->name' linestyle $ls linewidth 2"; if ($i->unit == "C") $gnuplot_cmd .= " axis x1y1,"; else $gnuplot_cmd .= " axis x1y2,"; } if (in_array( $i->id, $active_maxmin )) { /* Test maxmin */ $gnuplot_cmd .= "'data/$i->id.daily_extremes' every 1 using 1:3:4 title '$i->name (min/max)' with filledcurves linestyle $ls"; if ($i->unit == "C") $gnuplot_cmd .= " axis x1y1,"; else $gnuplot_cmd .= " axis x1y2,"; /* $gnuplot_cmd .= "'data/$i->id.daily_extremes' every 1 using 1:3 title '$i->name (min)' with steps linestyle $ls+20+1"; */ /* if ($i->unit == "C") */ /* $gnuplot_cmd .= " axis x1y1,"; */ /* else */ /* $gnuplot_cmd .= " axis x1y2,"; */ /* $gnuplot_cmd .= "'data/$i->id.daily_extremes' every 1 using 1:4 title '$i->name (max)' with steps linestyle $ls+20+2"; */ /* if ($i->unit == "C") */ /* $gnuplot_cmd .= " axis x1y1,"; */ /* else */ /* $gnuplot_cmd .= " axis x1y2,"; */ } } /* for ($i = 0; $i < $hygrometer_count; $i++) */ /* { */ /* $ls++; */ /* if (in_array( $hygrometer[$i], $active_sensors )) */ /* { */ /* $gnuplot_cmd .= "'data/$hygrometer[$i].log' using 1:3 title '$hygrometer[$i]' axis x1y2 linestyle $ls,"; */ /* } */ /* } */ $gnuplot_cmd = rtrim( $gnuplot_cmd, "," ); $gnuplot_cmd .= ";unset output;"; #echo "

$gnuplot_cmd

"; `echo "$gnuplot_cmd" | gnuplot`; ?>

Ser du ingen graf här kan du testa att välja PNG i st f SVG som bildformat nedan. "; } else { echo "\"Sensorplot."; } ?>


webcam logs

"); printf( "Sidan skapades på %0.3f sekunder.", $time ); printf("
"); system('uptime'); printf("

"); ?>