Gegeben sei: Installation von Debian Linux Version >= 3.0.
apt-get install digitemp rrdtool librrdp-perl
# Systemuser m. Zugriffsrechten auf serielle
# Schnittstellen anlegen:
useradd onewire -d /var/log/1wire -G dialout
mkdir -p /usr/local/bin /var/log/1wire
chown onewire /var/log/1wire
# Inventur des 1-Wire-Busses, erzeugt .digitemprc
cd /var/log/1wire
digitemp_DS9097U -s /dev/ttyS0 -v -i
chown onewire /var/log/1wire/.digitemprc
Script /usr/local/bin/1wiretemp fuer bis zu drei Sensoren
#!/bin/sh
cd /var/log/1wire
reading=`/usr/bin/digitemp_DS9097U -a -q -o 2`
d=`date +%s`
c1=`echo $reading | awk '{print ($2)?($2):("U")}'`
c2=`echo $reading | awk '{print ($3)?($3):("U")}'`
c3=`echo $reading | awk '{print ($4)?($4):("U")}'`
# Update RRD
/usr/bin/rrdtool update /var/log/1wire/temp.rrd $d:$c1:$c2:$c3
# Log
echo /usr/bin/rrdtool update /var/log/1wire/temp.rrd $d:$c1:$c2:$c3 >> /var/log/1wire/temp.log
ausfuehrbar machen:
chmod 755 /usr/local/bin/1wiretemp
RRD anlegen, als Vorlage dient /usr/share/doc/digitemp/rrdb/make_temps,
die Strings "T1","T2","T3" koennen durch eigene Angaben ersetzt werden.
#!/usr/bin/perl -w
use Time::Local;
use RRDp;
RRDp::start "/usr/bin/rrdtool";
RRDp::cmd "create /var/log/1wire/temp.rrd \
DS:T1:GAUGE:600:U:U \
DS:T2:GAUGE:600:U:U \
DS:T3:GAUGE:600:U:U \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MIN:0.5:1:600 \
RRA:MIN:0.5:6:700 \
RRA:MIN:0.5:24:775 \
RRA:MIN:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797";
RRDp::end;
ausfuehrbar machen, ausfuehren und Inhaber der Datei setzen:
chmod 755 /tmp/make_temps
/tmp/make_temps
chown onewire /var/log/1wire/temp.rrd
Cronjob /etc/cron.d/1wiretemp
* * * * * onewire cd /var/log/1wire && /usr/local/bin/1wiretemp
Zum Schluss nochmal die Rechte gerade ziehen:
chown -R onewire /var/log/1wire
Fuer die Darstellung bedarf es eines mittleren CGI-Scripts ...
... und einiger kleiner CGI-Scripte:#!/bin/bash rrd="/var/log/1wire/temp.rrd" starttime="-1day" endtime=$( date +%s ) width="400" height="100" label="" case "$1" in daily) starttime="-1day" ;; weekly) starttime="-1week" ;; monthly) starttime="-1month" ;; yearly) starttime="-1year" ;; esac # Output a HTML header for the PNG image to follow echo 'Content-type: image/png' echo # Generate the graph # simple if [ 1 = 0 ]; then /usr/bin/rrdtool graph - --imgformat PNG \ --start $starttime --end $endtime \ --width $width --height $height \ DEF:T1=$rrd:T1:AVERAGE \ DEF:T2=$rrd:T2:AVERAGE \ DEF:T3=$rrd:T3:AVERAGE \ LINE1:T1#FF0000:'T1' \ LINE1:T2#8080FF:'T2' \ LINE1:T3#00FF00:'T3' fi # verbose if [ 1 = 0 ]; then /usr/bin/rrdtool graph - --imgformat PNG \ --start $starttime --end $endtime \ --width $width --height $height \ --vertical-label "°C" \ --title "Temperatur" \ COMMENT:'Sensor\:' \ DEF:T1=$rrd:T1:AVERAGE \ DEF:T2=$rrd:T2:AVERAGE \ DEF:T3=$rrd:T3:AVERAGE \ LINE2:T1#FF0000:'T1' \ AREA:T2#8080FF:'T2' \ LINE1:T3#00FF00:'T3' fi # fancy if [ 1 = 1 ]; then /usr/bin/rrdtool graph - --imgformat PNG \ --start $starttime --end $endtime \ --width $width --height $height \ --vertical-label "°C" \ --title "Temperatur" \ COMMENT:'Sensor\:' \ DEF:T1=$rrd:T1:AVERAGE \ DEF:T2=$rrd:T2:AVERAGE \ DEF:T2min=$rrd:T2:MIN \ DEF:T2max=$rrd:T2:MAX \ DEF:T3=$rrd:T3:AVERAGE \ CDEF:T22=T2,0,LE,T2min,UNKN,IF \ CDEF:T23=T2,0,GT,T2max,UNKN,IF \ LINE2:T1#FF0000:'T1' \ AREA:T22#80A0FF:' ' \ AREA:T23#8060FF:'T2' \ LINE1:T3#00FF00:'T3' fi exit
/usr/lib/cgi-bin/temp.month#!/bin/bash /usr/lib/cgi-bin/temp weekly
/usr/lib/cgi-bin/temp.year#!/bin/bash /usr/lib/cgi-bin/temp monthly
(Das kann man natuerlich viel schoener machen. Immerhin sorgt der ,,Umweg'' ueber die zusaetzlichen Scripte temp.* dafuer, dass keine Code-Injection in das Shell-Script moeglich ist.)#!/bin/bash /usr/lib/cgi-bin/temp yearly
chmod 755 /usr/lib/cgi-bin/temp /usr/lib/cgi-bin/temp.weekly
chmod 755 /usr/lib/cgi-bin/temp.monthly /usr/lib/cgi-bin/temp.yearly
Schliesslich noch etwas HTML:
<html> <head> <title> temp stats </title> </head> <body> <p> <img src=/cgi-bin/temp> </p> <p> <img src=/cgi-bin/temp.week> </p> <p> <img src=/cgi-bin/temp.month> </p> <p> <img src=/cgi-bin/temp.year> </p> </body> </html>
Fuer zwei Sensoren kann beispielweise so aussehen:
DigiTemp v3.3.2 Copyright 1996-2004 by Brian C. Lane
GNU Public License v2.0 - http://www.brianlane.com
Turning off all DS2409 Couplers
..
Devices on the Main LAN
103079FF00080015 : DS1820/DS18S20/DS1920 Temperature Sensor
10E1C7000108004B : DS1820/DS18S20/DS1920 Temperature Sensor