Last active
February 4, 2020 16:37
-
-
Save thaarok/b70dff4369ff2f0a2afe to your computer and use it in GitHub Desktop.
Samsung TV/DVR remote control in PHP. Protocol description here: http://sc0ty.pl/2012/02/samsung-tv-network-remote-control-protocol/
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
<form action="remote.php" method="POST"> | |
<input type="text" name="channel" value="<?php echo htmlspecialchars(@$_POST["channel"]) ?>"><input type="submit" name="go" value="Go"> | |
</form> | |
<form action="remote.php" method="POST"> | |
<input type="submit" name="key" value="KEY_1"> | |
<input type="submit" name="key" value="KEY_2"> | |
<input type="submit" name="key" value="KEY_3"><br> | |
<input type="submit" name="key" value="KEY_4"> | |
<input type="submit" name="key" value="KEY_5"> | |
<input type="submit" name="key" value="KEY_6"><br> | |
<input type="submit" name="key" value="KEY_7"> | |
<input type="submit" name="key" value="KEY_8"> | |
<input type="submit" name="key" value="KEY_9"><br> | |
<input type="submit" name="key" value="KEY_CHDOWN"> | |
<input type="submit" name="key" value="KEY_0"> | |
<input type="submit" name="key" value="KEY_CHUP"> | |
<br><br> | |
<input type="submit" name="key" value="KEY_REC"> | |
<input type="submit" name="key" value="KEY_STOP"><br> | |
<input type="submit" name="key" value="KEY_MUTE"> | |
<input type="submit" name="key" value="KEY_GUIDE"> | |
<input type="submit" name="key" value="KEY_MENU"> | |
<br><br> | |
<table> | |
<tr><td><input type="submit" name="key" value="KEY_TOOLS"></td><td><input type="submit" name="key" value="KEY_UP"></td><td><input type="submit" name="key" value="KEY_INFO"></td></tr> | |
<tr><td><input type="submit" name="key" value="KEY_LEFT"></td><td><input type="submit" name="key" value="KEY_ENTER"></td><td><input type="submit" name="key" value="KEY_RIGHT"></td></tr> | |
<tr><td><input type="submit" name="key" value="KEY_RETURN"></td><td><input type="submit" name="key" value="KEY_DOWN"></td><td><input type="submit" name="key" value="KEY_EXIT"></td></tr> | |
</table> | |
</form> | |
<form action="remote.php" method="POST"> | |
<input type="text" name="key" value="<?php echo htmlspecialchars(@$_POST["key"]) ?>"><input type="submit" value="OK"> | |
</form> | |
<pre> | |
<?php | |
if(isset($_POST["go"])) goToChannel($_POST["channel"]); | |
if(isset($_POST["key"])) sendkey($_POST["key"]); | |
function goToChannel($channel){ | |
$numbers = str_split(str_pad($channel, 4, "0", STR_PAD_LEFT)); | |
foreach($numbers as $number){ | |
sendkey("KEY_".$number); | |
} | |
} | |
// protocol description: http://sc0ty.pl/2012/02/samsung-tv-network-remote-control-protocol/ | |
// list of key codes: http://wiki.samygo.tv/index.php5/D-Series_Key_Codes | |
function sendkey($key){ | |
$address = gethostbyname('10.0.0.6'); // IP of TV here | |
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
if($socket === false) echo "socket_create(): ".socket_strerror(socket_last_error())."\n"; | |
$result = socket_connect($socket, $address, 55000); | |
if($result === false) echo "socket_connect(): ".socket_strerror(socket_last_error($socket))."\n"; | |
$packet = pack("C*", 0x00, 0x13, 0x00, 0x69, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x2e, 0x69, 0x61, 0x70, 0x70, 0x2e, 0x73, | |
0x61, 0x6d, 0x73, 0x75, 0x6e, 0x67, 0x38, 0x00, 0x64, 0x00, 0x10, 0x00, 0x4d, 0x54, 0x41, 0x75, | |
0x4d, 0x43, 0x34, 0x77, 0x4c, 0x6a, 0x49, 0x79, 0x4d, 0x67, 0x3d, 0x3d, 0x14, 0x00, 0x63, 0x6d, | |
0x46, 0x75, 0x5a, 0x47, 0x39, 0x74, 0x55, 0x6d, 0x56, 0x74, 0x62, 0x33, 0x52, 0x6c, 0x53, 0x55, | |
0x51, 0x3d, 0x0c, 0x00, 0x62, 0x58, 0x6c, 0x53, 0x5a, 0x57, 0x31, 0x76, 0x64, 0x47, 0x55, 0x3d); | |
socket_write($socket, $packet); | |
$keycode = base64_encode($key); | |
$payload = pack("C*", 0x00, 0x00, 0x00, 0x00).pack("C*",strlen($keycode),0x00).$keycode; | |
$packet = pack("C*", 0x00, 0x13, 0x00, 0x69, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x2e, 0x69, 0x61, 0x70, 0x70, 0x2e, 0x73, | |
0x61, 0x6d, 0x73, 0x75, 0x6e, 0x67).pack("C*",strlen($payload)-1).$payload; | |
socket_write($socket, $packet); | |
socket_close($socket); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
merci