-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscover.php
More file actions
42 lines (34 loc) · 1.42 KB
/
Copy pathdiscover.php
File metadata and controls
42 lines (34 loc) · 1.42 KB
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
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Tapo\P110;
$creds = json_decode(file_get_contents(__DIR__ . '/credentials.json'), true);
$hosts = [];
for ($i = 1; $i <= 10; $i++) {
$hosts[] = "tp-plug-{$i}";
}
$hosts[] = 'tp-bulb-01';
$hosts[] = 'tp-bulb-02';
echo str_pad('HOST', 16) . str_pad('MODEL', 10) . str_pad('NAME', 16) . str_pad('STATUS', 8) . str_pad('POWER', 10) . str_pad('TODAY', 10) . str_pad('MONTH', 10) . "IP\n";
echo str_repeat('-', 96) . "\n";
foreach ($hosts as $host) {
try {
$dev = new P110($host, $creds['email'], $creds['password']);
$info = $dev->getDeviceInfo();
$name = base64_decode($info['nickname']);
$status = $info['device_on'] ? 'ON' : 'OFF';
$power = '-';
$today = '-';
$month = '-';
try {
$energy = $dev->getEnergyUsage();
$power = round($energy['current_power'] / 1000, 1) . 'W';
$today = round($energy['today_energy'] / 1000, 2) . 'kWh';
$month = round($energy['month_energy'] / 1000, 2) . 'kWh';
} catch (\Throwable $e) {
// device doesn't support energy monitoring
}
echo str_pad($host, 16) . str_pad($info['model'], 10) . str_pad($name, 16) . str_pad($status, 8) . str_pad($power, 10) . str_pad($today, 10) . str_pad($month, 10) . $info['ip'] . "\n";
} catch (\Throwable $e) {
echo str_pad($host, 16) . "OFFLINE\n";
}
}