digitemp-rrdgraph/sbin/send_info.php

38 lines
1.2 KiB
PHP
Raw Permalink 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);
2024-01-30 18:35:21 +09:00
$digitemp = new Orrisroot\DigiTemp($config['digitemp'], APPDIR.'/'.$config['digitemp_config']);
$rrdtemp = new Orrisroot\Rrd\Temperature(APPDIR.'/'.$config['database_dir']);
2020-06-09 16:02:25 +09:00
$num = $digitemp->getNumSensors();
$sensors = [];
for ($i = 0; $i < $num; ++$i) {
$id = $digitemp->getSensorId($i);
$rrdtemp->addSensor($id);
$sensors[] = $rrdtemp->readLastData($id);
}
$from = $config['mail_from'];
$from_name = $config['mail_from_name'];
$to = $config['mail_info_to'];
$subject = $config['mail_info_subject'];
2024-01-30 18:35:21 +09:00
$loader = new Twig\Loader\FilesystemLoader(APPDIR.'/'.$config['templates_dir']);
$twig = new Twig\Environment($loader);
2020-06-09 16:02:25 +09:00
$data = [
'from' => [
'name' => $from_name,
'email' => $from,
],
'sensors' => $sensors,
'url' => $config['url'],
];
$body = $twig->render($config['mail_info_template'], $data);
2024-01-30 18:35:21 +09:00
$from = new Orrisroot\Mail\Address($from_name, $from);
$tos = [new Orrisroot\Mail\Address($to, $to)];
Orrisroot\Mail\UTF8_Mailer::sendMail($from, $tos, $subject, $body);