|
|
@ -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); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
function getItems($db) { |
|
|
|
return $db->read('items'); |
|
|
|
} |
|
|
|
|
|
|
|
function setItems($db) { |
|
|
|
$items = $db->read('items'); |
|
|
|
$f3->route('GET /cron', function($f3) { |
|
|
|
$datestring = date('H').':'.date('i'); |
|
|
|
$model = new Item; |
|
|
|
$items = $model->find(['@ontime = ? or @offtime = ?', $datestring, $datestring]); |
|
|
|
|
|
|
|
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(); |
|
|
|