Browse Source

implement cron

master
Enzo Angiulli 4 years ago
parent
commit
a204b4aea0
  1. 53
      index.php
  2. 14
      ui/home.htm
  3. 2
      ui/layout.htm

53
index.php

@ -57,8 +57,11 @@ $f3->route('GET /api/items',
$f3->route('POST /sendsignal', function($f3) {
$post = json_decode($f3->get('BODY'), true);
// print_r($post);
// die;
$messages = sendsignal($post);
echo json_encode($messages);
});
function sendsignal($post) {
$iparray = preg_split('/\r\n|\r|\n/', $post['item']['ip']);
$messages = [];
switch ($post['item']['channel']) {
@ -84,8 +87,8 @@ $f3->route('POST /sendsignal', function($f3) {
array_push($messages, ['success' => false, 'message' => 'No channel set for these equipments']);
break;
}
echo json_encode($messages);
});
return $messages;
}
$f3->route('POST /del', function ($f3) {
$item = new Item;
@ -141,33 +144,25 @@ function wol($macAddress, $broadcastIP) {
}
}
$f3->route('GET /optomaon',
function($f3) {
$client = \Graze\TelnetClient\TelnetClient::factory();
$dsn = '192.168.0.100:23';
$client->setLineEnding(null);
$client->setPrompt("Optoma_PJ>");
$client->setPromptError("F");
$conn = $client->connect($dsn);
$client->setReadTimeout(1);
$response = $client->execute("~0000 1\r");
print_r($response);
});
$f3->route('GET /cron', function($f3) {
$datestring = date('H').':'.date('i');
$model = new Item;
$items = $model->find(['@ontime = ? or @offtime = ?', $datestring, $datestring]);
function getItems($db) {
return $db->read('items');
}
function setItems($db) {
$items = $db->read('items');
if (!empty($items)) {
$messages = [];
foreach ($items as $item) {
if (in_array(date('l'), $item['days'])) {
if ($item['ontime'] === $datestring) { $messages = sendsignal(['item' => $item, 'action' =>$item['oncommand']]);}
if ($item['offtime'] === $datestring) { $messages = sendsignal(['item' => $item, 'action' =>$item['offcommand']]);}
}
}
foreach ($messages as $message) {
echo date('Y.m.d'). ' ' .$datestring . ' '. $message['message'];
}
}
$f3->route('GET /userref',
function($f3) {
$f3->set('content','userref.htm');
echo View::instance()->render('layout.htm');
}
);
});
$f3->run();

14
ui/home.htm

@ -61,13 +61,13 @@
<div v-show="newitem.channel != ''">
<label for="days">
Days<br>
<label>monday<br><input type="checkbox" v-model="newitem.days" value="monday"></label>
<label>tuesday<br><input type="checkbox" v-model="newitem.days" value="tuesday"></label>
<label>wednesday<br><input type="checkbox" v-model="newitem.days" value="wednesday"></label>
<label>thursday<br><input type="checkbox" v-model="newitem.days" value="thursday"></label>
<label>friday<br><input type="checkbox" v-model="newitem.days" value="friday"></label>
<label>saturday<br><input type="checkbox" v-model="newitem.days" value="saturday"></label>
<label>sunday<br><input type="checkbox" v-model="newitem.days" value="sunday"></label>
<label>monday<br><input type="checkbox" v-model="newitem.days" value="Monday"></label>
<label>tuesday<br><input type="checkbox" v-model="newitem.days" value="Tuesday"></label>
<label>wednesday<br><input type="checkbox" v-model="newitem.days" value="Wednesday"></label>
<label>thursday<br><input type="checkbox" v-model="newitem.days" value="Thursday"></label>
<label>friday<br><input type="checkbox" v-model="newitem.days" value="Friday"></label>
<label>saturday<br><input type="checkbox" v-model="newitem.days" value="Saturday"></label>
<label>sunday<br><input type="checkbox" v-model="newitem.days" value="Sunday"></label>
</label>
</div>
<div v-show="['udp', 'telnet'].indexOf(newitem.channel) >= 0">

2
ui/layout.htm

@ -13,7 +13,7 @@
<meta name="msapplication-starturl" content="/192.168.0.200">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>IzzoControl</title>
<base href="<?php echo $SCHEME.'://'.$HOST.':'.$PORT.$BASE.'/'; ?>" />
<link rel="stylesheet" href="lib/code.css" type="text/css" />
<link rel="stylesheet" href="ui/css/base.css" type="text/css" />
<link rel="stylesheet" href="ui/css/theme.css" type="text/css" />

Loading…
Cancel
Save