digitemp-rrdgraph/sbin/update.php

32 lines
945 B
PHP
Raw Normal View History

2020-06-09 16:02:25 +09:00
<?php
define('APPDIR', dirname(__DIR__));
require_once APPDIR.'/vendor/autoload.php';
$config = json_decode(file_get_contents(APPDIR.'/etc/config.json'), true);
$digitemp = new \Orrisroot\DigiTemp($config['digitemp'], APPDIR.'/'.$config['digitemp_config']);
$rrdtemp = new \Orrisroot\Rrd\Temperature(APPDIR.'/'.$config['database_dir']);
$num = $digitemp->getNumSensors();
for ($i = 0; $i < $num; ++$i) {
$id = $digitemp->getSensorId($i);
$value = $digitemp->readSensor($i);
$rrdtemp->addSensor($id);
$now = time();
$rrdtemp->update($id, $now, $value);
}
2021-10-28 14:42:00 +09:00
$types = [
'hour' => [1, 3, 6, 12],
'day' => [1, 3],
'week' => [1, 2],
'month' => [1, 3, 6],
'year' => [1, 3, 5, 10],
];
foreach ($types as $type => $nums) {
foreach ($nums as $num) {
$fpath = APPDIR.'/'.$config['images_dir'].'/graph-'.(1 === $num ? '' : $num).$type.'.png';
$rrdtemp->outputGraph($type, $num, $fpath);
}
2020-06-09 16:02:25 +09:00
}