|
@ -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>"); |
|
|
if (!empty($items)) { |
|
|
$client->setPromptError("F"); |
|
|
$messages = []; |
|
|
$conn = $client->connect($dsn); |
|
|
foreach ($items as $item) { |
|
|
$client->setReadTimeout(1); |
|
|
if (in_array(date('l'), $item['days'])) { |
|
|
$response = $client->execute("~0000 1\r"); |
|
|
if ($item['ontime'] === $datestring) { $messages = sendsignal(['item' => $item, 'action' =>$item['oncommand']]);} |
|
|
print_r($response); |
|
|
if ($item['offtime'] === $datestring) { $messages = sendsignal(['item' => $item, 'action' =>$item['offcommand']]);} |
|
|
}); |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
foreach ($messages as $message) { |
|
|
function getItems($db) { |
|
|
echo date('Y.m.d'). ' ' .$datestring . ' '. $message['message']; |
|
|
return $db->read('items'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function setItems($db) { |
|
|
|
|
|
$items = $db->read('items'); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
$f3->route('GET /userref', |
|
|
|
|
|
function($f3) { |
|
|
|
|
|
$f3->set('content','userref.htm'); |
|
|
|
|
|
echo View::instance()->render('layout.htm'); |
|
|
|
|
|
} |
|
|
} |
|
|
); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$f3->run(); |
|
|
$f3->run(); |
|
|