camImagesProcess
|
Сортировка изображений с веб-камеры
$src='/var/www/media/webcam'; // откуда брать фотографии
clearTimeout('camImagesTimer');
$base_path='/var/www/dvr/unsorted';
$dst='/var/www/dvr/sorted';
safe_exec('chown pi:pi -Rf '.$base_path.'/*');
safe_exec('chmod 0777 -f '.$base_path.'/*');
setTimeout('camImagesTimer','runScript("camImagesProcess");',10*60);
if (is_dir($base_path)) {
if ($dir = @opendir($base_path)) {
while (($file = readdir($dir)) !== false) {
if ($file!='.' && $file!='..' && is_dir($base_path.'/'.$file)) {
$src=$base_path.'/'.$file;
echo $src.'<br/>';
processLine($src." -> ".$dst."/%Y/%m - %F/%d/".$file);
}
}
closedir($dir);
}
} else {
echo "Cannot open $base_path";
}
processLine("CLEAR ".$dst." 30 DAYS OLD");
|
checkFreeSpace
|
Проверка свободного места на диске
$max_usage=90; //%
$output=array();
exec('df',$output);
//var_dump($output);
$problems=0;
$problems_details='';
foreach($output as $line) {
if (preg_match('/(\d+)% (\/.+)/',$line,$m))
$proc=$m[1];
$path=$m[2];
if ($proc>$max_usage) {
$problems++;
$problems_details.="$path: $proc; ";
}
//echo "$path: $proc%<br/>";
}
sg("ThisComputer.SpaceProblems",$problems);
sg("ThisComputer.SpaceProblems_Details",$problems_details);
setTimeOut('checkFreeSpace','runScript("checkFreeSpace");',5*60);
|
rebootSystem
|
Перезапуск системы
$filename = ROOT . '/database_backup/db.sql';
$mysqlDumpPath = "/usr/bin/mysqldump";
$mysqlDumpParam = " --user=" . DB_USER . " --password=" . DB_PASSWORD;
$mysqlDumpParam .= " --no-create-db --add-drop-table --databases " . DB_NAME;
if (file_exists($filename)) rename($filename, $filename . '.prev');
exec($mysqlDumpPath . $mysqlDumpParam . " > " . $filename);
say("Подготовка к перезагрузке",2);
setTimeout("shutdownTimer","safe_exec('shutdown -r now');",15);
|
roomsIdleDelay
|
Изменение таймаутов датчиков движения в зависимости от времени суток
if (timeBetween('23:00','6:00')){
setGlobal('Kitchen.IdleDelay', 90); //Движение на кухне
setGlobal('Hall.IdleDelay', 10); //Движение на холле
}
else{
setGlobal('Kitchen.IdleDelay', 600); //Движение на кухне
setGlobal('Hall.IdleDelay', 180); //Движение на холле
}
|
shutDown
|
Выключение системы
$filename = ROOT . '/database_backup/db.sql';
$mysqlDumpPath = "/usr/bin/mysqldump";
$mysqlDumpParam = " --user=" . DB_USER . " --password=" . DB_PASSWORD;
$mysqlDumpParam .= " --no-create-db --add-drop-table --databases " . DB_NAME;
if (file_exists($filename)) rename($filename, $filename . '.prev');
exec($mysqlDumpPath . $mysqlDumpParam . " > " . $filename);
say("Подготовка к выключению",2);
setTimeout("shutdownTimer","safe_exec('shutdown -h now');",15);
|
childCamSnapshotToTelegram
|
//делаем снимок
callMethod('Camera01.takeSnapshot');
$path = ROOT.'cms/images/'.gg('Camera01.snapshot');
//отправляем картинку в телеграмм
include_once(DIR_MODULES . 'telegram/telegram.class.php');
$telegram_module = new telegram();
$telegram_module->sendImageToAll($path);
|
lobbyCamSnapshotToTelegram
|
//делаем снимок
callMethod('Camera03.takeSnapshot');
$path = ROOT.'cms/images/'.gg('Camera03.snapshot');
//$path = ROOT.'cms/images/cam_hall.jpg';
//$path = 'http://192.168.1.121/cgi-bin/currentpic.cgi?width=1920&height=1080';
//$ch = curl_init('http://192.168.1.121/cgi-bin/currentpic.cgi?width=1920&height=1080');
//$fp = fopen($path, 'wb');
//curl_setopt($ch, CURLOPT_FILE, $fp);
//curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_exec($ch);
//curl_close($ch);
//fclose($fp);
//отправляем картинку в телеграмм
include_once(DIR_MODULES . 'telegram/telegram.class.php');
$telegram_module = new telegram();
$telegram_module->sendImageToAll($path);
|
manageConnectService
|
Включение/выключение сервиса синхронизации через облако
include_once(DIR_MODULES.'connect/connect.class.php');
$cn=new connect();
$cn->getConfig();
if ($params['start']) {
$cn->config['CONNECT_SYNC']='1';
$cn->saveConfig();
}
if ($params['stop']) {
$cn->config['CONNECT_SYNC']='0';
$cn->saveConfig();
}
echo $cn->config['CONNECT_SYNC'];
|
manageWebCamMotion
|
Включение/выключение детектора движений на камере
if ($params['start']) {
DebMes("Starting web-cam motion detection");
getURL('http://localhost:8080/0/detection/start',0);
}
if ($params['stop']) {
DebMes("Stopping web-cam motion detection");
getURL('http://localhost:8080/0/detection/pause',0);
}
|
manageWebCamService
|
Включение/выключение вебкамеры
if ($params['start']) {
safe_exec('cp /etc/motion/motion_enabled /etc/default/motion');
safe_exec('service motion start');
}
if ($params['stop']) {
safe_exec('cp /etc/motion/motion_disabled /etc/default/motion');
safe_exec('service motion stop');
}
|
whoIsHome
|
//if ((time()-(getGlobal('XiOpenclose01.updated ')))<=(60*60*4)) {
//вернулся домой
if ((getGlobal('RedmiAnna.online') || getGlobal('MiBandAnna.online') || (getGlobal('PhoneAnna.online') == 1)) && !getGlobal('Anna.atHome')) {
setGlobal('Anna.atHome', 1);
}
if ((getGlobal('RedmiSergey.online') || getGlobal('MiBandSergey.online') || (getGlobal('PhoneSergey.online') == 1) || (getGlobal('PhoneSergey_2.online') == 1)) && !getGlobal('Sergey.atHome')) {
setGlobal('Sergey.atHome', 1);
}
if ((getGlobal('RedmiNadya.online') || getGlobal('MiBandNadya.online') || (getGlobal('PhoneNadya.online') == 1)) && !getGlobal('Nadya.atHome')) {
setGlobal('Nadya.atHome', 1);
}
if ((getGlobal('PhoneLida.online') == 1) && !getGlobal('Lida.atHome')) {
setGlobal('Lida.atHome', 1);
}
//}
if ((time()-(getGlobal('XiOpenclose01.updated ')))<=1800) {
//покинул дом
if (!getGlobal('RedmiAnna.online') && !getGlobal('MiBandAnna.online') && (getGlobal('PhoneAnna.online') == 2) && getGlobal('Anna.atHome')) {
setGlobal('Anna.atHome', 0);
}
if (!getGlobal('RedmiSergey.online') && !getGlobal('MiBandSergey.online') && (getGlobal('PhoneSergey.online') == 2) && (getGlobal('PhoneSergey_2.online') == 2) && getGlobal('Sergey.atHome')) {
setGlobal('Sergey.atHome', 0);
}
if (!getGlobal('RedmiNadya.online') && !getGlobal('MiBandNadya.online') && (getGlobal('PhoneNadya.online') == 2) && getGlobal('Nadya.atHome')) {
setGlobal('Nadya.atHome', 0);
}
if ((getGlobal('PhoneLida.online') == 2) && getGlobal('Lida.atHome')) {
setGlobal('Lida.atHome', 0);
}
}
|
openYandexRadio
|
//читать первое сообщение для справки
//https://mjdm.ru/forum/viewtopic.php?f=5&t=518
runScript('playClose');
$address='10.1.30.49'; // ip-адрес планшета
$service_port='7999';
$in='run:ru.yandex.radio'; // команда для отправки
//$in='tts:проверка'; // команда для отправки
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "<br/>\n";
return 0;
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
return 0;
}
socket_write($socket, $in, strlen($in));
socket_close($socket);
setGlobal('ThisComputer.audioSource', 'YandexRadio');
|
playClose
|
//getURL('http://localhost/popup/app_player.html?ajax=1&command=close&play_terminal=Plane_7007_3G',0);
$command = 'выключи музыку';
callAPI('/api/module/yadevices','GET',array('station'=>1,'command'=>$command));
setGlobal('ThisComputer.audioSource', 'Mute');
|
playCollection
|
playMedia('/mnt/usbstorage/Music/','Plane_7007_3G');
//playMedia('//192.168.1.44/share/Music/','Plane_7007_3G');
setGlobal('ThisComputer.audioSource', 'Collection');
|
playFavoriteMusic
|
// вытягиваем историю из переменной
$alreadyPlayed=gg("AlreadyPlayedMusic");
if (!$alreadyPlayed) {
$alreadyPlayed='0';
}
// выбираем случайную папку
$rec=SQLSelectOne("SELECT * FROM media_favorites WHERE ID NOT IN (".$alreadyPlayed.") ORDER BY RAND()");
if (!$rec['ID']) {
// папок больше не осталось, поэтому выбираем случайную и сбрасываем истоирю
$rec=SQLSelectOne("SELECT * FROM media_favorites ORDER BY RAND()");
$alreadyPlayed='0';
}
if ($rec['ID']) {
// добавляем выбранную папку в историю
$alreadyPlayed.=','.$rec['ID'];
sg("AlreadyPlayedMusic",$alreadyPlayed);
// запускаем на проигрывание
$collection=SQLSelectOne("SELECT * FROM collections WHERE ID=".(int)$rec['COLLECTION_ID']);
$path=$collection['PATH'].$rec['PATH'];
playMedia($path);
//setTimeOut('VLCPlayer_update',"callMethod('VLCPlayer.update');",10);
}
|
playPause
|
getURL('http://localhost/popup/app_player.html?ajax=1&command=pause&play_terminal=Plane_7007_3G',0);
|
playPlay
|
getURL('http://localhost/popup/app_player.html?ajax=1&command=pl_repeat&play_terminal=Plane_7007_3G',0);
|
playRadio70th
|
//getURL(BASE_URL.ROOTHTML.'apps/shoutcast.html?mode=playnow&terminal=Plane_7007_3G&station_id=1638134',0);
$command = 'включи музыку семядисятых';
callAPI('/api/module/yadevices','GET',array('station'=>1,'command'=>$command));
setGlobal('ThisComputer.audioSource', 'Radio70th');
|
playRadioCountry
|
//getURL('http://localhost/popup/app_101ru.html?ajax=1&op=playstation&id=162', 0);
$command = 'включи кантри';
callAPI('/api/module/yadevices','GET',array('station'=>1,'command'=>$command));
setGlobal('ThisComputer.audioSource', 'RadioCountry');
|
playRadioJazz
|
//getURL(BASE_URL.ROOTHTML.'apps/shoutcast.html?mode=playnow&terminal=Plane_7007_3G&station_id=1416985',0);
$command = 'включи джаз';
callAPI('/api/module/yadevices','GET',array('station'=>1,'command'=>$command));
setGlobal('ThisComputer.audioSource', 'RadioJazz');
|
playRadioLounge
|
//getURL('http://localhost/popup/app_101ru.html?ajax=1&op=playstation&id=55&terminal=Plane_7007_3G', 0);
//getURL(BASE_URL.ROOTHTML.'apps/shoutcast.html?mode=playnow&terminal=Plane_7007_3G&station_id=805077',0);
$command = 'включи лаундж';
callAPI('/api/module/yadevices','GET',array('station'=>1,'command'=>$command));
setGlobal('ThisComputer.audioSource', 'RadioLounge');
|
playRadioRelaxFM
|
//getURL('http://localhost/popup/app_101ru.html?ajax=1&op=playstation&id=184', 0);
//читать первое сообщение для справки
//https://mjdm.ru/forum/viewtopic.php?f=5&t=518
/*
$address='10.1.30.49'; // ip-адрес планшета
$service_port='7999';
$in='play:http://ic7.101.ru:8000/a200'; // команда для отправки
//$in='tts:проверка'; // команда для отправки
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "<br/>\n";
return 0;
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
return 0;
}
socket_write($socket, $in, strlen($in));
socket_close($socket);
*/
//SetTimeOut('nvol100','say("Громкость сообщений 100 процентов");',2);
//say("Громкость сообщений сто процентов", 2);
$command = 'включи радио релакс';
callAPI('/api/module/yadevices','GET',array('station'=>1,'command'=>$command));
setGlobal('ThisComputer.audioSource', 'RadioRelaxFM');
|
playRadioWorkOff
|
$command = 'включи личную станцию';
callAPI('/api/module/yadevices','GET',array('station'=>1,'command'=>$command));
setGlobal('ThisComputer.audioSource', 'RadioWorkOff');
|
playRandom
|
getURL('http://localhost/popup/app_player.html?ajax=1&command=pl_random&play_terminal=Plane_7007_3G',0);
//getURL('http://localhost/popup/app_player.html?ajax=1&command=pl_random',0);
|
setNVolume100
|
//читать первое сообщение для справки
//https://mjdm.ru/forum/viewtopic.php?f=5&t=518
$address='10.1.30.49'; // ip-адрес планшета
$service_port='7999';
$in='volume:100'; // команда для отправки
//$in='tts:проверка'; // команда для отправки
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "<br/>\n";
return 0;
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
return 0;
}
socket_write($socket, $in, strlen($in));
socket_close($socket);
//SetTimeOut('nvol100','say("Громкость сообщений 100 процентов");',2);
//say("Громкость сообщений сто процентов", 2);
|
sendMailProductList
|
Отправка списка продуктов на почту
$servername = "localhost";
$username = "root";
$password = "rootpsw";
$dbname = "db_terminal";
$from = "alicesirotkina@gmail.com";
$to = "sirotkinaanya@yandex.ru";
$subject = "Shop list";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT ID, TITLE, List_Qty FROM shopping_list_items";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$shopList .= "<input type='checkbox'>".$row["TITLE"]. ": " . $row["List_Qty"]. "шт.<br>";
}
} else {
$shopList = "Список покупок пуст.";
}
$body =
'<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Список продуктов</title>
</head>
<body>
<div>
<h1>Незабудьте купить:</h1>
<p>'.$shopList.'
</p>
</div>
</body>
</html>';
SendMail_html($from, $to, $subject, $body);
mysqli_close($conn);
|
shopList_ShowAsText
|
$servername = "localhost";
$username = "root";
$password = "rootpsw";
$dbname = "db_terminal";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT ID, TITLE, List_Qty FROM shopping_list_items";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $row["TITLE"]. ": " . $row["List_Qty"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
|
shopList_Telegram
|
include_once(DIR_MODULES . 'telegram/telegram.class.php');
$telegram_module = new telegram();
$telegram_module->sendMessageToAll("test message to all");
$servername = "localhost";
$username = "root";
$password = "rootpsw";
$dbname = "db_terminal";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT ID, TITLE, List_Qty FROM shopping_list_items";
$result = mysqli_query($conn, $sql);
$mes_line = "Не забудьте купить:\n";
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$mes_line .= $row["TITLE"]. ": " . $row["List_Qty"]. "\n";
}
} else {
$mes_line = "Список покупок пуст.";
}
$telegram_module->sendMessageToAll($mes_line);
mysqli_close($conn);
|
coldFilterChange
|
//сбрасываем флаг
setGlobal('ColdFilter.startFlag',0);
//и через пять секунд устанавливаем в 1
SetTimeOut('tmrColdFilterFlag','setGlobal("ColdFilter.startFlag",1);', 5);
|
devicesNotResponse
|
Выполняется каждый час
echo "OK";
if (!getGlobal('AirValvePosition.alive')){
//say('Внимание форточка не работает',1);
}
if (!getGlobal('ColdCounter.alive') || !getGlobal('HotCounter.alive')){
say('Внимание счетчик воды не работает',1);
}
if (!getGlobal('Sensor_voltage01.alive')){
say('Внимание датчик углекислого газа не работает',1);
}
|
hotFilterChange
|
//сбрасываем флаг
setGlobal('HotFilter.startFlag',0);
//и через пять секунд устанавливаем в 1
SetTimeOut('tmrHotFilterFlag','setGlobal("HotFilter.startFlag",1);', 5);
|
motionDetected
|
Сработал детектор движения на веб-камере
DebMes("Motion detected: ".serialize($params));
callMethod('MotionSensorCam.motionDetected');
setTimeOut('motionDetectedTimer','runScript("camImagesProcess");',10);
if (getGlobal('ThisComputer'.'.'.'WebCamMotionAuto')) {
setTimeOut('stopWebCamDetection', " runScript('manageWebCamMotion', array('stop'=>'1'));", (int)('60'));
}
|
NobodyHome
|
Срабатывает, когда никого дома нет
say('Включаю режим экономии', 1);
callMethod('EconomMode'.'.'.'activate');
if (getGlobal('ThisComputer'.'.'.'WebCamMotionAuto')) {
runScript('manageWebCamMotion', array('start'=>'1'));
}
|
SomebodyHome
|
Срабатывает в том случае, когда кто-то появился дома
callMethod('EconomMode'.'.'.'deactivate');
runScript('reportStatus', array());
if (getGlobal('ThisComputer'.'.'.'WebCamMotionAuto')) {
setTimeOut('stopWebCamDetection', " runScript('manageWebCamMotion', array('stop'=>'1'));", (int)('60'));
}
|
startUp
|
Система загружена
say('Система загружена', 1);
runScript('tellIPAddress', array());
//переводим преер в рандомный режим
runScript('playRandom');
runScript('restartSAMBA');
|
turnOffEverything
|
Выключить все приборы
//$objects=array('Switch1','Switch2','Switch3');
//foreach($objects as $o) {
// callMethod($o.'.turnOff');
//}
callMethod('Dimmer1.turnOff');
callMethod('Dimmer2.turnOff');
callMethod('Dimmer04.turnOff'); //LED лента в коридоре
callMethod('KitchenWorkZoneDimmer.turnOff');
callMethod('KitchenLedStrip.turnOff');
callMethod('Relay01.turnOff'); // свет в холле
setGlobal('XiRgb01.brightness', 0);
callMethod('RadioOnOff.turnOff');
|
sceneKitchenWork
|
setGlobal('KitchenWorkZoneDimmer.level', 100);
setGlobal('KitchenLedStrip.level', 0);
setGlobal('Dimmer1.level', 0);
setGlobal('Dimmer2.level', 0);
setGlobal('XiRgb01.brightness', 0);
setGlobal('LoggiaBlinds.level', 100); //опускаем шторы на балконе
setGlobal('ThisComputer.lightScene', 'KitchenWork');
|
sceneLunch
|
setGlobal('KitchenWorkZoneDimmer.level', 0);
setGlobal('KitchenLedStrip.level', 0);
setGlobal('Dimmer1.level', 0);
setGlobal('Dimmer2.level', 75);
setGlobal('XiRgb01.brightness', 0);
setGlobal('ThisComputer.lightScene', 'Lunch');
|
sceneNightLight
|
setGlobal('KitchenWorkZoneDimmer.level', 0);
setGlobal('KitchenLedStrip.level', 0);
setGlobal('Dimmer1.level', 0);
setGlobal('Dimmer2.level', 0);
setGlobal('XiRgb01.color', '#ff6500'); //warm white
setGlobal('LoggiaBlinds.level', 100); //опускаем шторы на балконе
setGlobal('ThisComputer.lightScene', 'NightLight');
|
sceneNightTV
|
setGlobal('KitchenLedStrip.level', 45);
setGlobal('KitchenWorkZoneDimmer.level', 0);
setGlobal('Dimmer1.level', 0);
setGlobal('Dimmer2.level', 0);
setGlobal('XiRgb01.brightness', 0);
setGlobal('LoggiaBlinds.level', 100); //опускаем шторы на балконе
setGlobal('ThisComputer.lightScene', 'NightTV');
|
sceneToSleep
|
setGlobal('KitchenWorkZoneDimmer.level', 0);
setGlobal('KitchenLedStrip.level', 0);
setGlobal('Dimmer1.level', 0);
setGlobal('Dimmer2.level', 0);
setGlobal('XiRgb01.brightness', 0);
setGlobal('LoggiaBlinds.level', 100); //опускаем шторы на балконе
setGlobal('ThisComputer.lightScene', 'ToSleep');
|