herzklopfen
10.07.2005, 10:56
hi,
ich habe einen temperatur-sensor gebastelt, wie es ihn zu tausenden mit Anleitungen im Internet gibt.
Zunächst das positive: der Sensor funktioniert ;-)
eine abfrage wie diese:
./digitemp -l/var/log/temperature -a -o"%d.%m.%Y %H:%M:%S Sensor %s C: %.2C"
ergibt:
10.07.2005 10:30:13 Sensor 0 C: 26.19¿üo@
nun gibts dazu ein perl-script:
#!/usr/bin/perl
#
# v3:every line of the legend in a seperate line
# min/max temp in the legend for every sensor
# switch of errormessages when having a wrong sensorline
# with [input] tell_wrong_sensors=0
# v2: 21.08. - seperate dbfiles
#
# You must call digitemp like this
# ./digitemp -l/var/log/temperature -a -o"%d.%m.%Y %H:%M:%S Sensor %s C: %.2C *"
# Output in lofile is:
# 31.10.2000 11:20:52 Sensor 1 C: 8.78 *
#
use strict;
use Time::Local;
use Net::FTP;
use Net::SMTP;
use MIME::Lite;
use File::Basename;
use Getopt::Long;
use Temperature::Config;
use Temperature::Rrd;
use Temperature::Logreader;
use Temperature::Transfer;
my $version = 3;
print "This is $0 V$version\n";
my $debug = 0;
# evtl. read another inifile
my ($opt_inifile, $opt_help);
GetOptions('help' => \$opt_help, 'inifile=s' => \$opt_inifile);
&help if $opt_help;
my $cfg = Temperature::Config->new(inifile=>$opt_inifile,debug=>$debug);
# create a new rrd-database
my $rrd = Temperature::Rrd->new(
rrdtool_fn => $cfg->getini_rrdtool_fn,
db_fn => $cfg->getini_rrd_database_fn,
pic_fn => $cfg->getini_pic_fn,
sensors => $cfg->getini_sensors,
heartbeat => $cfg->getini_heartbeat,
linewidth=> $cfg->getini_linewidth,
pic_width=> $cfg->getini_pic_width,
pic_height=> $cfg->getini_pic_height,
debug => $debug,
);
# open log
my $log = Temperature::Logreader->new(ini=>$cfg);
# put logline into rrd-database
# read lines from logfile and update rrd-database
while (my $line = $log->get) {
next unless $line->{valid};
#
# put your definitions of "mad values" for your sensors here, examples:
# next if $line->{value} = '85.00';
# next if $line->{value} > 120;
# etc.
#
# set last, min and max value for epoch and temperature
$cfg->log_linestatistics(
$line->{sensor},$line->{epoch},$line->{value});
$rrd->update(
sensor=>$line->{sensor},
epoch=>$line->{epoch},
value=>$line->{value}
);
}
if ($cfg->log_statistic(what=>"linesread_interesting") == 0) {
print "I could not find lines in the time I am interested in.\n";
print "No lines, no database, no graphics.\n";
die;
}
&create_graphics($cfg);
$cfg->send_mail_on_panic;
# Transfer graphics via ftp or cp
Temperature::Transfer->transfer(ini=>$cfg);
$cfg->show_statistics();
&local_panic_actions;
# eventually send mail here
# clean up
unlink $cfg->getini_rrd_database_fn;
printf "Regular end of %s\n", basename($0);
exit;
sub help {
printf "Usage: %s [--inifile=%s.ini]\n",
basename($0), basename($0,'.pl');
exit;
}
sub create_graphics {
my $cfg = shift;
my %legends;
# Build legend for graphic
foreach ($cfg->sensors) {
$legends{$_} = $cfg->sensor_info($_, "description");
# put max and min temperature to the legends
$legends{$_} .= sprintf ", min %s degrees C", $cfg->log_statistic(what=>"temperature",minmax=>"min",sensor=>$_);
$legends{$_} .= sprintf ", max %s degrees C", $cfg->log_statistic(what=>"temperature",minmax=>"max",sensor=>$_);
}
my %colors;
foreach ($cfg->sensors) {
$colors{$_} = $cfg->sensor_info($_, "color");
}
$rrd->create_graphics(
begin_time => $cfg->log_statistic(what=>'epoch',minmax=>'min',sensor=>$cfg->first_sensor),
end_time => $cfg->log_statistic(what=>'epoch',minmax=>'max',sensor=>$cfg->first_sensor),
legends => \%legends,
colors => \%colors,
title => $cfg->getini_picture_title,
comment => $cfg->get_picture_comment,
);
}
sub local_panic_actions {
my $be_quiet=1;
return if $be_quiet;
foreach my $s ($cfg->sensors) {
my $last = $cfg->log_statistic(what=>'temperature', minmax=>'last', sensor=>$s);
my $panic = $cfg->sensor_info($s, "critical_temperature");
printf "Last temperature Sensor %d is %d degrees Celsius.\n",
$s, $last;
if ($last >= $panic) {
printf "Panic! Last temperature is %d degrees Celsius, panictemp is %d\n",
$last, $panic;
}
}
}
bei der ausführung bekomme ich diese fehlermeldung:
This is temperatur2www.pl V3
Can't call method "val" on an undefined value at Temperature/Config.pm line 317.
die Datei hängt in der Anlage. Weiss jemand Rat?
Ziel ist es, eine Grafische temperaturkurve fürs Web darzustellen.
Grüße
Herzklopfen
PS die ini-Datei gibts auf Wunsch auch noch...
ich habe einen temperatur-sensor gebastelt, wie es ihn zu tausenden mit Anleitungen im Internet gibt.
Zunächst das positive: der Sensor funktioniert ;-)
eine abfrage wie diese:
./digitemp -l/var/log/temperature -a -o"%d.%m.%Y %H:%M:%S Sensor %s C: %.2C"
ergibt:
10.07.2005 10:30:13 Sensor 0 C: 26.19¿üo@
nun gibts dazu ein perl-script:
#!/usr/bin/perl
#
# v3:every line of the legend in a seperate line
# min/max temp in the legend for every sensor
# switch of errormessages when having a wrong sensorline
# with [input] tell_wrong_sensors=0
# v2: 21.08. - seperate dbfiles
#
# You must call digitemp like this
# ./digitemp -l/var/log/temperature -a -o"%d.%m.%Y %H:%M:%S Sensor %s C: %.2C *"
# Output in lofile is:
# 31.10.2000 11:20:52 Sensor 1 C: 8.78 *
#
use strict;
use Time::Local;
use Net::FTP;
use Net::SMTP;
use MIME::Lite;
use File::Basename;
use Getopt::Long;
use Temperature::Config;
use Temperature::Rrd;
use Temperature::Logreader;
use Temperature::Transfer;
my $version = 3;
print "This is $0 V$version\n";
my $debug = 0;
# evtl. read another inifile
my ($opt_inifile, $opt_help);
GetOptions('help' => \$opt_help, 'inifile=s' => \$opt_inifile);
&help if $opt_help;
my $cfg = Temperature::Config->new(inifile=>$opt_inifile,debug=>$debug);
# create a new rrd-database
my $rrd = Temperature::Rrd->new(
rrdtool_fn => $cfg->getini_rrdtool_fn,
db_fn => $cfg->getini_rrd_database_fn,
pic_fn => $cfg->getini_pic_fn,
sensors => $cfg->getini_sensors,
heartbeat => $cfg->getini_heartbeat,
linewidth=> $cfg->getini_linewidth,
pic_width=> $cfg->getini_pic_width,
pic_height=> $cfg->getini_pic_height,
debug => $debug,
);
# open log
my $log = Temperature::Logreader->new(ini=>$cfg);
# put logline into rrd-database
# read lines from logfile and update rrd-database
while (my $line = $log->get) {
next unless $line->{valid};
#
# put your definitions of "mad values" for your sensors here, examples:
# next if $line->{value} = '85.00';
# next if $line->{value} > 120;
# etc.
#
# set last, min and max value for epoch and temperature
$cfg->log_linestatistics(
$line->{sensor},$line->{epoch},$line->{value});
$rrd->update(
sensor=>$line->{sensor},
epoch=>$line->{epoch},
value=>$line->{value}
);
}
if ($cfg->log_statistic(what=>"linesread_interesting") == 0) {
print "I could not find lines in the time I am interested in.\n";
print "No lines, no database, no graphics.\n";
die;
}
&create_graphics($cfg);
$cfg->send_mail_on_panic;
# Transfer graphics via ftp or cp
Temperature::Transfer->transfer(ini=>$cfg);
$cfg->show_statistics();
&local_panic_actions;
# eventually send mail here
# clean up
unlink $cfg->getini_rrd_database_fn;
printf "Regular end of %s\n", basename($0);
exit;
sub help {
printf "Usage: %s [--inifile=%s.ini]\n",
basename($0), basename($0,'.pl');
exit;
}
sub create_graphics {
my $cfg = shift;
my %legends;
# Build legend for graphic
foreach ($cfg->sensors) {
$legends{$_} = $cfg->sensor_info($_, "description");
# put max and min temperature to the legends
$legends{$_} .= sprintf ", min %s degrees C", $cfg->log_statistic(what=>"temperature",minmax=>"min",sensor=>$_);
$legends{$_} .= sprintf ", max %s degrees C", $cfg->log_statistic(what=>"temperature",minmax=>"max",sensor=>$_);
}
my %colors;
foreach ($cfg->sensors) {
$colors{$_} = $cfg->sensor_info($_, "color");
}
$rrd->create_graphics(
begin_time => $cfg->log_statistic(what=>'epoch',minmax=>'min',sensor=>$cfg->first_sensor),
end_time => $cfg->log_statistic(what=>'epoch',minmax=>'max',sensor=>$cfg->first_sensor),
legends => \%legends,
colors => \%colors,
title => $cfg->getini_picture_title,
comment => $cfg->get_picture_comment,
);
}
sub local_panic_actions {
my $be_quiet=1;
return if $be_quiet;
foreach my $s ($cfg->sensors) {
my $last = $cfg->log_statistic(what=>'temperature', minmax=>'last', sensor=>$s);
my $panic = $cfg->sensor_info($s, "critical_temperature");
printf "Last temperature Sensor %d is %d degrees Celsius.\n",
$s, $last;
if ($last >= $panic) {
printf "Panic! Last temperature is %d degrees Celsius, panictemp is %d\n",
$last, $panic;
}
}
}
bei der ausführung bekomme ich diese fehlermeldung:
This is temperatur2www.pl V3
Can't call method "val" on an undefined value at Temperature/Config.pm line 317.
die Datei hängt in der Anlage. Weiss jemand Rat?
Ziel ist es, eine Grafische temperaturkurve fürs Web darzustellen.
Grüße
Herzklopfen
PS die ini-Datei gibts auf Wunsch auch noch...