pmayer
October 24, 2016, 10:50pm
1
Habe das gerade mal gegengetestet… ich bekomme da einen PHP Fehler:
Fatal error: Uncaught Error: Call to undefined function hg_invoke() in /var/lib/homegear/www/rpc/index.php:52
Stack trace:
#0 {main}
thrown in /var/lib/homegear/www/rpc/index.php on line 52
Homegear version 0.7.0-1446
@sathya ?
pmayer
October 24, 2016, 11:06pm
2
Hab das Script gerade mal auf die das Homegear Objekt umgeschrieben (quick hack):
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Homegear RPC Server</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="jumbotron">
<div class="container">
<img style="float: left; margin-top: 13px; margin-right: 40px" src="Logo.png" />
<h2>Your</h2>
<h1>Homegear RPC Server</h1>
<h2>welcomes you!</h2>
</div>
</div>
<div class="container marketing">
<div class="row">
<div style="height: 350px" class="col-lg-4">
<span class="glyphicon glyphicon-education" style="font-size: 140px"></span>
<h2>Wiki</h2>
<p style="height: 40px">For help and tutorials visit the Homegear Wiki.</p>
<p><a class="btn btn-default" href="https://homegear.eu" role="button">Go there »</a></p>
</div><!-- /.col-lg-4 -->
<div style="height: 350px" class="col-lg-4">
<span class="glyphicon glyphicon-wrench" style="font-size: 140px"></span>
<h2>Reference</h2>
<p style="height: 40px">Visit the Homegear reference for information about using this RPC server.</p>
<p><a class="btn btn-default" href="https://www.homegear.eu/index.php/Homegear_Reference" role="button">Go there »</a></p>
</div><!-- /.col-lg-4 -->
<div style="height: 350px" class="col-lg-4">
<span class="glyphicon glyphicon-comment" style="font-size: 140px"></span>
<h2>Forum</h2>
<p style="height: 40px">If you still don't know, what to do, get help in our forum.</p>
<p><a class="btn btn-default" href="https://forum.homegear.eu" role="button">Go there »</a></p>
</div><!-- /.col-lg-4 -->
</div><!-- /.row -->
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">Device Overview</div>
<div class="panel-body"><p>Here's a list of all devices known to Homegear.</p></div>
<table class="table">
<thead><tr><th>Name</th><th>Family</th><th>ID</th><th>Serial Number</th><th>Type</th><th>Interface</th><th>Firmware</th></tr></thead>
<?php
$hg = new \Homegear\Homegear();
$families = $hg->listFamilies();
$familyNames = array();
foreach($families as $value)
{
$familyNames[$value["ID"]] = $value["NAME"];
}
$devices = $hg->listDevices(false, array("FAMILY", "ID", "ADDRESS", "TYPE", "FIRMWARE"));
foreach($devices as $value)
{
//$info = hg_invoke("getDeviceInfo", $value["ID"], array("NAME", "INTERFACE"));
$info = $hg->getDeviceInfo($value["ID"], array("NAME", "INTERFACE"));
echo "<tr>";
echo "<td>".$info["NAME"]."</td>";
echo "<td>".$familyNames[$value["FAMILY"]]."</td>";
echo "<td>".($value["ID"] > 999999 ? "0x".dechex($value["ID"]) : $value["ID"])."</td>";
echo "<td>".$value["ADDRESS"]."</td>";
echo "<td>".$value["TYPE"]."</td>";
echo "<td>".$info["INTERFACE"]."</td>";
echo "<td>".$value["FIRMWARE"]."</td>";
echo "</tr>";
}
?>
</table>
</div>
</div>
<footer>
<p class="pull-right"><a href="#">Back to top</a></p>
<p>© 2014-2016 Homegear UG</p>
</footer>
</div>
</body>
</html>
Allerdings bringt das homegear komplett zum Absturz:
root@homegearpi:/var/lib/homegear/www/rpc# ps aux | grep homegear
homegear 12208 4.8 4.5 432816 43584 ? TLsl 01:01 0:05 /usr/bin/homegear -u homegear -g homegear -p /var/run/homegear/homegear.pid
homegear 12503 0.2 2.0 108248 19112 ? SLsl 01:01 0:00 homegear -c /etc/homegear/ -rse
homegear 12520 0.5 2.7 432816 26204 ? S 01:03 0:00 /usr/bin/homegear -u homegear -g homegear -p /var/run/homegear/homegear.pid
homegear 12522 0.0 0.3 6660 2960 ? R 01:03 0:00 addr2line 0x20c4d8 -f -C -e /usr/lib/libhomegear-base.so.1
root 12524 0.0 0.2 5888 1900 pts/1 S+ 01:03 0:00 grep homegear
listFamilies
funktioniert noch, bei listDevices
steigt er aus.
sathya
October 25, 2016, 6:49am
3
Hey @pmayer ,
Da hat sich ein Fehler in “listDevices” im letzten Nightly eingeschlichen. Im aktuellen (Versionsnummer ist gleichgeblieben) ist dieser korrigiert.
Die “hg_”-Funktionen habe ich mal entfernt, daher ging es nicht mehr. Ich hatte vergessen, dass ich diese noch im Webinterface verwendet hatte… Deine Änderungen baue ich gleich mal ein.
Viele Grüße
Sathya
1 Like
pmayer
October 25, 2016, 6:00pm
4
Hab die index.php
dann doch noch mal aufgeräumt und ein wenig error handling eingeführt:
<?php
$hgDevices = [];
$hgVersion = '-';
$hgError = false;
try {
$hg = new \Homegear\Homegear();
$hgVersion = explode(' ', $hg->getVersion())[1];
$families = $hg->listFamilies();
$familyNames = [];
foreach ($families as $value) {
$familyNames[$value["ID"]] = $value["NAME"];
}
$rawDevices = $hg->listDevices(false, ["FAMILY", "ID", "ADDRESS", "TYPE", "FIRMWARE"]);
foreach ($rawDevices as $item) {
$info = $hg->getDeviceInfo($item["ID"], ["NAME", "INTERFACE"]);
$hgDevices[] = [
'name' => $info["NAME"],
'family' => $familyNames[$item["FAMILY"]],
'id' => ($item["ID"] > 999999 ? "0x" . dechex($item["ID"]) : $item["ID"]),
'address' => $item["ADDRESS"],
'type' => $item["TYPE"],
'interface' => (array_key_exists("INTERFACE", $info) ? $info["INTERFACE"] : " "),
'firmware' => $item["FIRMWARE"]
];
}
} catch (\Exception $e) {
$hgError = $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Homegear RPC Server</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="jumbotron">
<div class="container">
<small class="pull-right">
<b>Version:</b> <?= $hgVersion ?>
</small>
<img style="float: left; margin-top: 13px; margin-right: 40px" src="Logo.png"/>
<h2>Your</h2>
<h1>Homegear RPC Server</h1>
<h2>welcomes you!</h2>
</div>
</div>
<div class="container marketing">
<div class="row">
<div style="height: 350px" class="col-lg-4">
<span class="glyphicon glyphicon-education" style="font-size: 140px"></span>
<h2>Documentation</h2>
<p style="height: 40px">For help and tutorials visit the Homegear documentation.</p>
<p><a class="btn btn-default" href="https://doc.homegear.eu" role="button">Go there »</a></p>
</div><!-- /.col-lg-4 -->
<div style="height: 350px" class="col-lg-4">
<span class="glyphicon glyphicon-wrench" style="font-size: 140px"></span>
<h2>Reference</h2>
<p style="height: 40px">Visit the Homegear reference for information about using this RPC server.</p>
<p><a class="btn btn-default" href="https://ref.homegear.eu" role="button">Go there »</a></p>
</div><!-- /.col-lg-4 -->
<div style="height: 350px" class="col-lg-4">
<span class="glyphicon glyphicon-comment" style="font-size: 140px"></span>
<h2>Forum</h2>
<p style="height: 40px">If you still don't know, what to do, get help in our forum.</p>
<p><a class="btn btn-default" href="https://forum.homegear.eu" role="button">Go there »</a></p>
</div><!-- /.col-lg-4 -->
</div><!-- /.row -->
<div class="row">
<?php
if ($hgError === false) {
?>
<div class="panel panel-default">
<div class="panel-heading">
Device Overview
</div>
<?php
if (count($hgDevices)) {
?>
<div class="panel-body">
<p>Here's a list of all devices known to Homegear.</p>
</div>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Family</th>
<th>ID</th>
<th>Serial Number</th>
<th>Type</th>
<th>Interface</th>
<th>Firmware</th>
</tr>
</thead>
<tbody>
<?php
foreach ($hgDevices as $item) {
echo '<tr>' . PHP_EOL;
foreach ($item AS $value) {
echo '<td>' . htmlspecialchars($value) . '</td>' . PHP_EOL;
}
echo '</tr>' . PHP_EOL;
}
?>
</tbody>
</table>
<?php
} else {
?>
<div class="panel-body">
<div class="alert alert-info">
No devices known to Homegear yet.
</div>
</div>
<?php
}
?>
</div>
<?php
} else {
?>
<div class="alert alert-danger">
Can't connect to the Homegear service.<br>
<b>Error: </b>
<?= htmlspecialchars($hgError) ?>
</div>
<?php
}
?>
</div>
<footer>
<p class="pull-right"><a href="#">Back to top</a></p>
<p>© 2014-<?= date('Y') ?> Homegear UG (haftungsbeschränkt)</p>
</footer>
</div>
</body>
</html>
1 Like