homekit/localwebsite/handlers/MiscHandler.php
2024-02-18 02:20:03 +03:00

41 lines
1.2 KiB
PHP

<?php
class MiscHandler extends RequestHandler
{
public function GET_sensors_page() {
global $config;
$clients = [];
foreach ($config['temphumd_servers'] as $key => $params) {
$cl = new TemphumdClient(...$params);
$clients[$key] = $cl;
$cl->readSensor();
}
$this->tpl->set(['sensors' => $clients]);
$this->tpl->set_title('Датчики');
$this->tpl->render_page('sensors.twig');
}
public function GET_cams_stat() {
global $config;
list($ip, $port) = explode(':', $config['ipcam_server_api_addr']);
$body = jsonDecode(file_get_contents('http://'.$ip.':'.$port.'/api/timestamp/all'));
header('Content-Type: text/plain');
$date_fmt = 'd.m.Y H:i:s';
foreach ($body['response'] as $cam => $data) {
$fix = date($date_fmt, $data['fix']);
$start = date($date_fmt, $data['motion_start']);
$motion = date($date_fmt, $data['motion']);
echo "$cam:\n motion: $motion\n";
echo " motion_start: $start\n";
echo " fix: $fix\n\n";
}
}
}