-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_fbdect_energy.php
50 lines (47 loc) · 1.84 KB
/
get_fbdect_energy.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
<?php
$directaccess = true;
require_once('fritzbox.inc.php');
$CONFIG_FILENAME = 'data/config.xml';
//config.xml dateisystem rechte �berpr�fen
if(!file_exists($CONFIG_FILENAME)) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht finden!\n";
exit(1);
}
if(!is_readable($CONFIG_FILENAME)) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht lesen!\n";
exit(2);
}
//config.xml einlesen
libxml_use_internal_errors(true);
$xml = simplexml_load_file($CONFIG_FILENAME);
if (!$xml) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht laden!\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
exit(4);
}
$ResStr="";
if ($xml->backend->sidsource != "" || ($xml->fritzbox->username != "" || $xml->fritzbox->password != "") && $xml->fritzbox->address != "") {
$XMLdata = Fritzbox_GetHAactorsInfoXML();
if ($XMLdata != -1) {
foreach($xml->devices->device as $device) {
if ($device->vendor == "fbdect200") {
if (Fritzbox_GetHAactorDataFromXML($XMLdata,trim($device->address->masterdip),'present') == 1) {
$ResStr .= trim($device->id).":".Fritzbox_GetHAactorDataFromXML($XMLdata,trim($device->address->masterdip),'power').":".Fritzbox_GetHAactorDataFromXML($XMLdata,trim($device->address->masterdip),'energy')."|";
} else {
$ResStr .= trim($device->id).":-1:-1|";
}
}
}
}
else {
foreach($xml->devices->device as $device) {
if ($device->vendor == "fbdect200") {
$ResStr .= trim($device->id).":".Fritzbox_DECT200_Power($device->address->masterdip).":".Fritzbox_DECT200_Energie($device->address->masterdip)."|";
}
}
}
}
echo substr($ResStr, 0, strlen($ResStr)-1);
?>