forked from StefanNemeth/PHP-LG-SmartTV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
88 lines (73 loc) · 1.69 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* ----------------------------------------
* Example - PHP LG SmartTV API
* ----------------------------------------
* https://github.com/SteveWinfield/PHP-LG-SmartTV
**/
include 'smartTV.php';
/**
* Create instance of TV
* @param IP Address of TV
* (optional) @param Port of TV (default is 8080)
**/
$tv = new SmartTV('192.168.2.103'); // new SmartTV('192.168.2.103', 8080)
/**
* Set pairing key (if you don't know the pairing key
* execute the method ..->displayPairingKey() and it will
* be shown on your tv)
* @param Key
**/
$tv->setPairingKey(678887); // $tv->displayPairingKey();
/**
* Authenticate to the tv
* @except Login fails (wrong pairing key?)
**/
try {
$tv->authenticate();
} catch (Exception $e) {
die('Authentication failed, I am sorry.');
}
/**
* Set your volume up.
**/
$tv->processCommand(TV_CMD_VOLUME_UP);
/**
* Set your volume down
**/
$tv->processCommand(TV_CMD_VOLUME_DOWN);
/**
* Move your mouse
**/
$tv->processCommand(TV_CMD_MOUSE_MOVE, [ 'x' => 20, 'y' => 20 ]);
/**
* Trigger a mouse click
**/
$tv->processCommand(TV_CMD_MOUSE_CLICK);
/**
* Get current volume
**/
echo $tv->queryData(TV_INFO_VOLUME)->level;
/**
* Get current channel name
**/
echo $tv->queryData(TV_INFO_CURRENT_CHANNEL)->chname;
/**
* Save a screenshot
**/
file_put_contents('screen.jpeg', $tv->queryData(TV_INFO_SCREEN));
/**
* Change channel (Channel VIVA)
**/
// Get channel list
$channels = $tv->queryData(TV_INFO_CHANNEL_LIST);
// Channel name
$channelName = 'VIVA';
// Search for channel $channelName
foreach ($channels as $channel) {
if ($channel->chname == $channelName) {
// Change channel
$tv->processCommand(TV_CMD_CHANGE_CHANNEL, $channel);
break;
}
}