Ok, hier die Statusanzeige. Auch das ist runtergebrochen direkt auf meine Bedürfnisse. Wer ein bischen PHP/HTML kann, kann sich das natürlich weiter anpassen. (Hint: Credentials wie weiter oben erwähnt)
Code:
<html>
<head>
<META HTTP-EQUIV="refresh" CONTENT="60">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Lupusec XT2 Status</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#999999" vlink="#990000" alink="#666666"><!--mstheme--><font face="Arial, Arial, Helvetica">
<style type="text/css">
body {
background-color:#ddd;
font-family: Arial, 'Arial', sans-serif;
}
.sensortable
{
width:100%;
font-weight:normal;
font-size:12;
border: 1px solid black;
}
.statustable
{
width:100%;
font-weight:bold;
font-size:14;
border: 1px solid black;
}
.armtable
{
width:100%;
font-weight:bold;
font-size:24;
border: 1px solid black;
padding: 30px;
}
table {
border-collapse: collapse;
}
table, th, td {
border: 0px solid black;
}
th, td {
padding: 0px 3px 0px 3px;
}
</style>
<?
// Dieses Script liest die Sensoren und deren Daten aus einer Lupus XT2 Plus aus und stellt die Stati in einer Tabelle im Webfront dar
include 'LupusCredentials.php';
// Gerätetypen
$typen = array("4" => "Türkontakt", "16" => "Tag Reader", "37" => "Keypad", "46" => "Sirene");
// -----------------------------------------------------------------------------
// ab hier ist nichts mehr anzupassen
// Login
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result=curl_exec ($ch);
if ( $result == false ) {
$bkcolor="red";
$color="white";
$Modus = 'Anlage ausser Betrieb';
$html .= "<table class='statustable'>";
$html .= "<tr bgcolor='{$bkcolor}' style='font-size:24; color:{$color};'>";
$html .= "<td align='center' ><b><br/>{$Modus}<br/> </b></td></tr>";
$html .= "</table>";
echo $html;
die;
}
// Sensorliste lesen
$sensorliste = "http://".$ip."/action/deviceListGet";
curl_setopt($ch, CURLOPT_URL,$sensorliste);
$result=curl_exec ($ch);
// Umwandeln von JSON in ein Array
$result = str_replace("\t", "", $result);
$json_sens = json_decode($result, true);
$generalstatus = "http://".$ip."/action/panelCondGet";
curl_setopt($ch, CURLOPT_URL,$generalstatus);
$result=curl_exec ($ch);
curl_close ($ch);
$result = str_replace("\t", "", $result);
$json_stat = json_decode($result, true);
$updates = $json_stat['updates'];
$gsm_ok = $updates['sig_gsm_ok'];
$gsm_signal = $updates['sig_gsm'];
if ( $gsm_ok == "1" ) {
$gsm_ok = 'Ok';
} else {
$gsm_ok = 'Fehler!';
$gsm_signal = "0";
}
if ($gsm_signal == '{WEB_MSG_NA}' ){
$gsm_ok = 'Fehler 2!';
$gsm_signal = "0";
}
$Forms = $json_stat['forms'];
$Area1 = $Forms['pcondform1'];
$mode1 = $Area1['mode']; // Modus: 0 unscharf, 1 scharf, 2 home1, 3 home2, 4 home3
// jeweilge Zone als Index des neuen Arrays $sensoren verwenden und dieses nach Index (=Zone) sortieren
foreach ($json_sens['senrows'] as $sensor)
{
$zone = $sensor['zone'];
$sensoren[$zone] = $sensor;
}
ksort($sensoren);
// HTML-Ausgabe erstellen
$html = "\n<table class='sensortable'>\n";
$html .= "\n<tr>\n<td><b>Sensor</b></td>\n<td><b>offen</b></td>\n<td><b>Batt.</b></td>\n<td><b>Funk</b></td>\n</tr>\n";
foreach ($sensoren as $sensor)
{
$status = @GetTextBetween($sensor['status'], '{WEB_MSG_DC_', '}');
if ( $status != "" ) {
$html .= SensorOut( 0, $sensor );
}
}
$html .= "\n</table>\n";
$html .= "\n<table class='sensortable'>\n";
$html .= "\n<tr>\n<td><b>Sensor+Batt.</b></td>\n\n<td><b>Funk</b></td>\n<td style='border-left: 1px solid black;' ><b>Sensor+Batt.</b></td>\n\n<td><b>Funk</b></td>\n</tr>\n";
$col = 0;
foreach ($sensoren as $sensor)
{
$status = @GetTextBetween($sensor['status'], '{WEB_MSG_DC_', '}');
if ( $status == "" ) {
if ( $col == 0 ) $html .= "\n<tr>";
$html .= SensorOut( 1, $sensor );
if ( $col == 1 ) $html .= "\n</tr>\n";
$col = 1- $col;
}
}
$html .= "\n</table>\n";
// Armierung Status
$bkcolor="lime";
$color="black";
$Modus = "unscharf";
switch ($mode1) {
case "0":
$bkcolor="red";
$color="white";
$Modus = "unscharf";
break;
case "1":
$bkcolor="lime";
$color="black";
$Modus = "SCHARF!";
break;
case "2":
$bkcolor="yellow";
$color="black";
$Modus = "Home1";
break;
case "3":
$bkcolor="yellow";
$color="black";
$Modus = "Home2";
break;
case "4":
$bkcolor="yellow";
$color="black";
$Modus = "Home3";
break;
}
$html .= "\n<table class='armtable'>";
$html .= "\n<tr bgcolor='{$bkcolor}' color:{$color}' style='padding: 10px;'>";
$html .= "\n<td style='padding: 10px;' align='center' ><b>{$Modus} </b></td></tr>";
$html .= "\n</table>\n";
// GSM-Status
$html .= "\n<table class='statustable'>";
$html .= "\n<tr>\n<td><b>Status</b></td>\n<td><b>Wert</b></td>\n</tr>";
$html .= "\n<tr><td>GSM ok</td>\n<td>" . $gsm_ok . "</td>\n</tr>";
$html .= "\n<tr><td>GSM Signal</td>\n<td>" . $gsm_signal . "/9</td>\n</tr>";
$html .= "\n</table>\n";
//$html .= "<p></p>";
echo $html;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function SensorOut( $SnsTyp, $sensor )
{
$html = '';
$fault = 0;
// Daten aus Array zur besseren Anzeige bearbeiten
$status = @GetTextBetween($sensor['status'], '{WEB_MSG_DC_', '}');
$status = str_replace("CLOSE", "nein", $status);
$status = str_replace("OPEN", "ja", $status);
if ($sensor['rssi']=='{WEB_MSG_NA}') {
$rssi="n/a";
$fault = 1;
} else {
$rssi = substr($sensor['rssi'], -1);
}
$name = $sensor['name'];
$battery = $sensor['battery_ok'];
$battery = str_replace("1", "OK", $battery );
$battery = str_replace("0", "Schwach", $battery );
if ($fault==1) {
$battery = "unbek.";
$status = "unbek.";
}
$bkcolor="gray";
$color="black";
if ( strcasecmp($status, "nein" )== 0 ) { SetColors( 2, $bkcolor, $color );}
if (( strcasecmp($status, "ja" )== 0 ) or ( $fault == 1 )) { SetColors( 0, $bkcolor, $color );}
if ( $SnsTyp == 1 ) {
if ( $battery == "OK" ) {
SetColors( 2, $bkcolor, $color );
} else {
SetColors( 0, $bkcolor, $color );
}
$html .= "\n<td style='border-left: 1px solid black;' bgcolor='{$bkcolor}' style='color:{$color};'><b>" . $name . "</b></td>"; // battery_ok
} else {
// SensorName
$html .= "\n<tr bgcolor='{$bkcolor}' style='color:{$color};'>";
$html .= "\n<td><b>" . $name . "</b></td>"; // name
//Sensor Status
$html .= "\n<td align='center' >" . $status . "</td>"; // status
// Batterie
if ( strcasecmp($battery, "OK" )== 0 )
SetColors( 2, $bkcolor, $color );
else
SetColors( 0, $bkcolor, $color );
$html .= "\n<td align='center' bgcolor='{$bkcolor}' style='color:{$color};'>" . $battery . "</td>"; // battery_ok
}
// Funkleistung
SetColors( 2, $bkcolor, $color );
if ( strcasecmp($rssi, "5" )== 0 ) SetColors( 1, $bkcolor, $color );
if ( strcasecmp($rssi, "4" )== 0 ) SetColors( 1, $bkcolor, $color );
if ( strcasecmp($rssi, "3" )== 0 ) SetColors( 0, $bkcolor, $color );
if ( strcasecmp($rssi, "2" )== 0 ) SetColors( 0, $bkcolor, $color );
if ( strcasecmp($rssi, "1" )== 0 ) SetColors( 0, $bkcolor, $color );
if ( strcasecmp($rssi, "0" )== 0 ) SetColors( 0, $bkcolor, $color );
if ( $fault == 1 ) SetColors( 0, $bkcolor, $color );
$html .= "\n<td align='center' bgcolor='{$bkcolor}' style='color:{$color};'>";
if ( $fault==1) {
$html .= "n/a";
}else{
$html .= "{$rssi}/9";
}
$html .="\n</td>"; // rssi
if ( $SnsTyp <> 1 ) {
$html .= "\n</tr>\n";
}
return $html;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function SetColors( $level, &$backcolor, &$forecolor )
{
switch ($level) {
case 1:
$backcolor="yellow";
$forecolor="black";
break;
case 2:
$backcolor="lime";
$forecolor="black";
break;
default:
// case 0:
$backcolor="red";
$forecolor="white";
break;
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function GetTextBetween($string, $start, $end)
{
preg_match_all( "/$start(.*)$end/U", $string, $match );
return $match[1][0];
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
?>
</font></body>
</html>