summaryrefslogtreecommitdiff
path: root/localwebsite/handlers/MiscHandler.php
blob: 4e7291ee96db9ae84d696ec500a68b6e9e8fc823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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";
        }
    }

}