-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanting_camera.php
60 lines (48 loc) · 1.18 KB
/
planting_camera.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Camera Image Daemon
*
* @category Daemons
* @package Automated Planting 1.0
* @author Marcin Polak <mapoart@gmail.com>
* @license http://MarcinPolak.eu
* @version Release: 1.0
* @link http://MarcinPolak.eu/AutomatedPlanting
*/
require_once "bootstrap.php";
use Mapos\Daemon\Daemon;
use Mapos\Device\DeviceVideo;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$daemon = true;
$delay = 60;
$bigPictureDelay = 600;
if ($daemon) {
$daemon = new Daemon("plantcamera");
$daemon->setDelay($delay); //10 minutes
$daemon->start();
}
$logPath = 'logs/planting_camera.log';
$video = new DeviceVideo();
$video->setStoragePath(STORAGE_PATH);
$logger = new Logger('Video');
$logger->pushHandler(new StreamHandler($logPath, Logger::INFO));
$video->setLog($logger);
$run = 1;
$bigPictureTimer = 0;
while (1) {
if ($run == 1 || $bigPictureTimer > $bigPictureDelay) {
$video->captureImage();
$bigPictureTimer = 0;
}
$video->captureThumbnail();
$bigPictureTimer += $delay;
if ($daemon) {
$daemon->info("run " . $run);
//sleep(5);
$daemon->delay();
} else {
sleep($delay);
}
$run++;
}