zasílám upravený a hlavně funkční script
je třeba nainstalovat balíčky, které jsou napsány v prvním příspěvku
opravil jsem:
1. formát teploty již korektně zobrazen (+012.6) dříve bylo například (....+012.6)
2. ošetřen výpadek teplotního čidla tak aby hodnota stále držela na poslední naměřené
3. teploměr ukazuje i pod nulu
soubor.sh
#!/usr/bin/expect
set username [lindex $argv 1]
set password [lindex $argv 2]
spawn telnet [lindex $argv 0]
expect "Login:"
send "$username\r"
expect "Password:"
send "$password\r"
expect "> "
send "/system serial-terminal serial0\r"
expect "."
set timeout 9000
send \001
expect " "
send \0121
soubor.pl
#!/usr/bin/perl
#
use RRDs;
sub CreateGraph
{
my $rrd = $_[1];
my $img = $_[2];
RRDs::graph "$img/logger-$_[0].png",
"--lazy",
"-s -1$_[0]",
"-t Teplota nekde ",
"-h", "170", "-w", "500",
"-a", "PNG",
"-v stupne C",
"DEF:intemp=$rrd/logger.rrd:in-temp:AVERAGE",
"LINE2:intemp#66cc00:Cidlo1 Teplota",
"GPRINT:intemp:MIN: Min\\: %2.lf",
"GPRINT:intemp:MAX: Max\\: %2.lf",
"GPRINT:intemp:AVERAGE: Pru\\: %4.1lf",
"GPRINT:intemp:LAST: Aktualni\\: %2.lf stupne C\\n";
if ($ERROR = RRDs::error) { print "$0: unable to generate $_[0] graph: $ERROR\n"; }
}
# location of rrdtool databases
my $rrd = '/cesta kde maji byt obrazky';
# location where the images should go
my $img = '/cesta kde maji byt obrazky';
my $tempIN = `/kde se nachazi soubor/hafi_temp_dw.sh ipadresa jmeno heslo | grep [0-9]C | cut -d C -f 1`;
chop($tempIN);
# $tempIN =~ /^(.*)([\+\-]\d+\.\d+)C?$/;
$tempIN =~ /^(.*)([+-]\d+\.\d+)C?$/;
my $teplota1=$2;
if ($teplota1 >0 or $teplota1 < 0){
open (RW,">/kde se nachazi aktualni teplota/aktualni.txt") or die "nemohu otevrit soubor aktualni";
print RW $teplota1;
close RW;
}
else
{open (R,"/kde se nachazi aktualni teplota/aktualni.txt") or die "nemohu otevrit soubor aktualni";
$teplota1=<R>;
close R;
}
# if rrdtool database doesn't exist, create it
if (! -e "$rrd/logger.rrd")
{
print "creating rrd database ...\n";
RRDs::create "$rrd/logger.rrd",
"-s 300",
"DS:in-temp:GAUGE:600:-20:100",
# "DS:out-temp:GAUGE:600:-20:100",
"RRA:AVERAGE:0.5:1:576",
"RRA:AVERAGE:0.5:6:672",
"RRA:AVERAGE:0.5:24:732",
"RRA:AVERAGE:0.5:144:1460";
}
# insert value into rrd
RRDs::update "$rrd/logger.rrd", "-t", "in-temp", "N:$teplota1";
if ($ERROR = RRDs::error) { print "$0: unable to update $rrd/logger.rrd: $ERROR\n"; }
# create graphs
&CreateGraph("day",$rrd,$img);
&CreateGraph("week",$rrd,$img);
&CreateGraph("month",$rrd,$img);
&CreateGraph("year",$rrd,$img);
print $2
musite tedy mit 3 soubory: hafi_temp_dw.sh, rrd_logger.pl, aktualni.txt
cron zůstává stejný
odzkoušeno na routerboardu s os 3.xx