#!/bin/bash

# DigiTemp RRD logging script
# Copyright 1997-2002 by Brian C. Lane  www.brianlane.com

# Get the current temperatures, digitemp has been previously initalized with
# digitemp -i -s /dev/ttyS0 -o2 -a

# Run it in quiet mode, output is 0\tsensor#1\tsensor#2\tsensor#3

#reading=`/usr/local/bin/digitemp -a -q`
reading=`/root/digitemp-3.0.0/digitemp -a -q -c /root/.digitemprc`

# Diagnostic output
sensor1=`echo $reading | gawk '{print $2}'`
sensor2=`echo $reading | gawk '{print $3}'`
sensor3=`echo $reading | gawk '{print $4}'`

# Update the database
/usr/bin/rrdtool update /home/www/see.the.enemy.org/rrd/digitemp/digitemp.rrd N:$sensor1:$sensor2:$sensor3


cd /home/www/see.the.enemy.org/rrd/digitemp/
#/home/www/see.the.enemy.org/rrd/digitemp/create_graf.sh

rrd=digitemp.rrd
#rrd= /home/www/see.the.enemy.org/rrd/digitemp/digitemp.rrd

rrdtool graph MS4_daily.png --imgformat PNG   \
    --start -86400   \
    --title="daily"     --width 400 --height 100    \
    DEF:server=$rrd:sensor1:AVERAGE  \
    DEF:wohnzi=$rrd:sensor2:AVERAGE   \
    DEF:vorlauf=$rrd:sensor3:AVERAGE     \
    LINE1:wohnzi#00FF00:'Wohnzimmer'   \
    LINE1:server#0000FF:'Server' 1> /dev/null

rrdtool graph MS4_daily_vorlauf.png --imgformat PNG   \
    --start -86400   \
    --title="daily"     --width 400 --height 100    \
    DEF:server=$rrd:sensor1:AVERAGE  \
    DEF:wohnzi=$rrd:sensor2:AVERAGE   \
    DEF:vorlauf=$rrd:sensor3:AVERAGE     \
    LINE1:vorlauf#FF0000:'Vorlauf'  1> /dev/null


rrdtool graph MS4_weekly.png --imgformat PNG   \
    --start -604800 \
    --title="weekly" \
    --width 400 --height 100    \
    DEF:server=$rrd:sensor1:AVERAGE  \
    DEF:wohnzi=$rrd:sensor2:AVERAGE   \
    DEF:vorlauf=$rrd:sensor3:AVERAGE     \
    LINE1:wohnzi#00FF00:'Wohnzimmer'   \
    LINE1:vorlauf#FF0000:'Vorlauf'  \
    LINE1:server#0000FF:'Server' 1> /dev/null


rrdtool graph MS4_monthly.png --imgformat PNG   \
    --start -3170880 \
    --title="monthly" \
    --width 400 --height 100    \
    DEF:server=$rrd:sensor1:AVERAGE  \
    DEF:wohnzi=$rrd:sensor2:AVERAGE   \
    DEF:vorlauf=$rrd:sensor3:AVERAGE     \
    LINE1:wohnzi#00FF00:'Wohnzimmer'   \
    LINE1:vorlauf#FF0000:'Vorlauf'  \
    LINE1:server#0000FF:'Server' 1> /dev/null