Last active
February 13, 2016 20:45
-
-
Save kelsos/27e51d519f1e0e9ab2dd to your computer and use it in GitHub Desktop.
Raspberry control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: application/json'); | |
$kodi_param = $_GET['kodi']; | |
$hdmi_param = $_GET['hdmi']; | |
$result = []; | |
$kodi_set = isset($kodi_param); | |
$hdmi_set = isset($hdmi_param); | |
if ($kodi_set && $hdmi_set) { | |
$result["code"] = 400; | |
echo json_encode($result); | |
return; | |
} | |
if ($kodi_set) { | |
if ($kodi_param !== "off" && $kodi_param !== "on") { | |
$result["code"] = 400; | |
echo json_encode($result); | |
return; | |
} | |
if ($kodi_param === "off") { | |
exec('sudo /usr/bin/systemctl stop kodi.service', $output); | |
} else { | |
exec('sudo /usr/bin/systemctl start kodi.service', $output); | |
} | |
unset($output); | |
$output = []; | |
exec('sudo /usr/bin/systemctl status kodi.service', $output); | |
if ($kodi_param === "off" && strpos($output[2], 'inactive')) { | |
$result["code"] = 200; | |
} else if ($kodi_param === "on" && strpos($output[2], 'active')) { | |
$result["code"] = 200; | |
} else { | |
$result["code"] = 500; | |
} | |
echo json_encode($result); | |
} | |
if ($hdmi_set) { | |
if ($hdmi_param !== "off" && $hdmi_param !== "on") { | |
$result["code"] = 400; | |
echo json_encode($result); | |
return; | |
} | |
if ($hdmi_param === "off") { | |
exec('/opt/vc/bin/tvservice -o', $output); | |
} else { | |
exec('/opt/vc/bin/tvservice -p', $output); | |
} | |
unset($output); | |
$output = []; | |
exec('/opt/vc/bin/tvservice -s', $output); | |
if ($hdmi_param === "off" && strpos($output[0], 'off')) { | |
$result["code"] = 200; | |
} else if ($hdmi_param === "on" && !strpos($output[0], 'off')) { | |
$result["code"] = 200; | |
} else { | |
$result["code"] = 500; | |
} | |
echo json_encode($result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment