Browse Source

implement cron

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

51
index.php

@ -57,8 +57,11 @@ $f3->route('GET /api/items',
$f3->route('POST /sendsignal', function($f3) { $f3->route('POST /sendsignal', function($f3) {
$post = json_decode($f3->get('BODY'), true); $post = json_decode($f3->get('BODY'), true);
// print_r($post); $messages = sendsignal($post);
// die; echo json_encode($messages);
});
function sendsignal($post) {
$iparray = preg_split('/\r\n|\r|\n/', $post['item']['ip']); $iparray = preg_split('/\r\n|\r|\n/', $post['item']['ip']);
$messages = []; $messages = [];
switch ($post['item']['channel']) { 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']); array_push($messages, ['success' => false, 'message' => 'No channel set for these equipments']);
break; break;
} }
echo json_encode($messages); return $messages;
}); }
$f3->route('POST /del', function ($f3) { $f3->route('POST /del', function ($f3) {
$item = new Item; $item = new Item;
@ -141,33 +144,25 @@ function wol($macAddress, $broadcastIP) {
} }
} }
$f3->route('GET /optomaon', $f3->route('GET /cron', function($f3) {
function($f3) { $datestring = date('H').':'.date('i');
$client = \Graze\TelnetClient\TelnetClient::factory(); $model = new Item;
$dsn = '192.168.0.100:23'; $items = $model->find(['@ontime = ? or @offtime = ?', $datestring, $datestring]);
$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);
});
function getItems($db) { if (!empty($items)) {
return $db->read('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']]);}
} }
function setItems($db) {
$items = $db->read('items');
} }
$f3->route('GET /userref', foreach ($messages as $message) {
function($f3) { echo date('Y.m.d'). ' ' .$datestring . ' '. $message['message'];
$f3->set('content','userref.htm');
echo View::instance()->render('layout.htm');
} }
);
}
});
$f3->run(); $f3->run();

14
ui/home.htm

@ -61,13 +61,13 @@
<div v-show="newitem.channel != ''"> <div v-show="newitem.channel != ''">
<label for="days"> <label for="days">
Days<br> Days<br>
<label>monday<br><input type="checkbox" v-model="newitem.days" value="monday"></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>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>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>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>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>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>sunday<br><input type="checkbox" v-model="newitem.days" value="Sunday"></label>
</label> </label>
</div> </div>
<div v-show="['udp', 'telnet'].indexOf(newitem.channel) >= 0"> <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="msapplication-starturl" content="/192.168.0.200">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>IzzoControl</title> <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="lib/code.css" type="text/css" />
<link rel="stylesheet" href="ui/css/base.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" /> <link rel="stylesheet" href="ui/css/theme.css" type="text/css" />

Loading…
Cancel
Save