$s) { // Each run of the foreach looks at one line of input data. // Split the line into words, and place them in array $x $x = explode(" ",$s); // The sensor id is the 5th word in the line $sensorId = $x[4]; // The temperature is the 7th word in the line $temp = $x[6]; // If we have configured an output file for this sensor; if (array_key_exists($sensorId,$outFile)) { // Write the temperature out to the specified file // This may be usefull if you want to display temperatures on a webpage etc. shell_exec("echo $temp > ".$outFile[$sensorId]); } // Here comes the business end of this script. // Each sensor has its own round robin database (RRD) where data is stored. // First we check to see if the database file for this sensor exists; if ( !file_exists($rrdDir.$n.'.rrd') ) { // If not, we have to create it, // by running "rrdtool create" with a long list of arguments. // the first argument is the file name. // -s 300 sekunder mellom hver måling // 900, maks ant.sekunder uten data før verdi blir=unknown // -55 laveste temp for ds1820, 125 høyeste temp for ds1820 // This is the command to be executed in the unix shell. $command = $rrdtool.' create '.$rrdDir.$n.'.rrd '. '-s 300 '. // -s indicates the time between updates in sec. (5m is 300s) 'DS:temp:GAUGE:900:-55:125 '. // GAUGE indicates a spot measurment // 900 is the number of seconds that may pass before the value // is considered "unknown". // -55 is the minimum value the DS1820 can report // 125 is the maximum value the DS1820 can report 'RRA:AVERAGE:0.5:1:576 '. // two days at 5 min intervals 'RRA:AVERAGE:0.5:6:672 '. // two weeks at 30min(5*6) intervals 'RRA:AVERAGE:0.5:24:732 '. // two weeks at 2h intervals (120min/5min=24) 'RRA:AVERAGE:0.5:144:1460'; // two years at 12h intervals (12*60/5=144) // The awfully long command is constructed. Lets execute it. shell_exec($command); // uncomment for debugging //echo "\n\n".$command."\n\n"; } // rrd db is now sure to exist.. dump data into it. // uncomment to debug. // echo $db.": ".$rrd_insert[$db]." C\n"; // The update command is a lot shorter than the create command. // rrdtool update file.rrd N:[temperature] // N meanse NOW. You can also specify a unix timestamp here. $command = $rrdtool.' update '.$rrdDir.$n.'.rrd N:'.$temp; shell_exec($command); // again.. debugging.. //echo "\n$command\n"; } ?>