hier ist ein kleiner Skript, mit heisser Nadel gestrickt, um die UDP broadcasts aus dem Ekey zu verwerten.
<?
// UDP Data Block Structure
// long nVersion; // Version of the data (3)
// long nCmd; // action code (TERMCMD_ENTER,...)
// long nTerminalID; // Terminal ID
// char strTerminalSerial[14]; // Serial number of the Terminal (for net)
// char nRelayID; // Relay number
// char nReserved; // unused
// long nUserID; // User
// long nFinger; // Finger ID
// char strEvent[16]; // Event, which is to be triggered
// char sTime[16]; // yyyymmdd hhmmss
// unsigned short strName[1]; // Name of the User in Unicode, if available
// unsigned short strPersonalID[1]; // Personal ID + \0 (used only in Version 2)
$ekeyStringHex = "";
if ($IPS_SENDER == "Execute")
{
$ekeyStringHex ="0300000001000000f903100074657374383530393039303030390000680000000f0000000000000000000000000000000000000032303131313131392031323337323500610061006700000031000000";
}
else
{
$data = $IPS_VALUE;
for ($i=0; $i < strlen($data); $i++)
{
$ekeyStringHex .= str_pad(dechex(ord($data[$i])), 2, '0', STR_PAD_LEFT);
}
}
$ekeyString = preg_replace('/[\x00-\x1F\x7F]/', '', hextostr($ekeyStringHex))."
";
setvalue (38729 /*[ekey\EkeyAuswertung\EkeyString]*/, $ekeyString); // schreibt String in Variable EkeyString
$lenEkeyStringHex = strlen($ekeyStringHex);
$nVersion = intval(substr($ekeyStringHex,0,8)); // Version of the data (3)
$nCmd = intval(substr($ekeyStringHex,8,8)); // action code (TERMCMD_ENTER,...)
$nTerminalID = intval(substr($ekeyStringHex,16,8)); // Terminal ID
$strTerminalSerial = hextostr(substr($ekeyStringHex,24,28)); // Serial number of the Terminal (for net)
$nRelayID = intval(substr($ekeyStringHex,52,2)); // Relay number
$nReserved = intval(substr($ekeyStringHex,54,2)); // unused
$nUserID = intval(substr($ekeyStringHex,56,8)); // User
$nFinger = intval(substr($ekeyStringHex,64,8)); // Finger ID
$strEvent = hextostr(substr($ekeyStringHex,72,32)); // Event which is to be triggered
$sTimeStamp = hextostr(substr($ekeyStringHex,104,15)); // yyyymmdd hhmmss
$ekeyYear = hextostr(substr($ekeyStringHex,104,8));
$ekeyMonth = hextostr(substr($ekeyStringHex,112,4));
$ekeyDay = hextostr(substr($ekeyStringHex,116,4));
$ekeyHH = hextostr(substr($ekeyStringHex,122,4));
$ekeyMM = hextostr(substr($ekeyStringHex,126,4));
$ekeySS = hextostr(substr($ekeyStringHex,130,4));
$strName = preg_replace('/[\x00-\x1F\x7F]/', '', hextostr(substr($ekeyStringHex,134)));
$ekeyTimeStamp = $ekeyDay . "-" . $ekeyMonth . "-" . $ekeyYear . " " . $ekeyHH . ":" . $ekeyMM . ":" . $ekeySS;
$TerminalName = "no terminal defined";
echo "*" . $strTerminalSerial . "*";
switch ($strTerminalSerial) {
case "70008539090511":
$TerminalName = "Tiefgaragentor";
break;
case "80032703100503":
$TerminalName = "Treppenhaus_UG";
break;
case "70008509090009":
switch ($nFinger) {
case "9000000":
$TerminalName = "Erster Keller";
break;
default:
$TerminalName = "Lift";
}
break;
case "80100507100744":
$TerminalName = "Haustür_EG";
break;
case "70009006090011":
$TerminalName = "SE_Lift";
break;
case "80034024080052":
$TerminalName = "SE_Aussenhuelle";
break;
case "test8509090009":
$TerminalName = "Software-triggered";
break;
}
echo "*".$TerminalName."*";
$emailDebugBody = "nVersion : " . $nVersion . "
"
. "nCmd : ".$nCmd. "
"
. "nTerminalID : ".$nTerminalID. "
"
. "strTerminalSerial : ".$strTerminalSerial. "
"
. "nRelayID : ".$nRelayID. "
"
. "nReserved : ".$nReserved. "
"
. "nUserID : ".$nUserID. "
"
. "nFinger : ".$nFinger. "
"
. "ekeyYear : ".$ekeyYear. "
"
. "ekeyMonth : ".$ekeyMonth. "
"
. "ekeyDay : ".$ekeyDay. "
"
. "ekeyHH : ".$ekeyHH. "
"
. "ekeyMM : ".$ekeyMM. "
"
. "ekeySS : ".$ekeySS. "
"
. "lenEkeyStringHex : ".$lenEkeyStringHex. "
"
. "strName : " . $strName. "
"
. "ekeyTimeStamp : " . $ekeyTimeStamp ;
$emailHeader = $strName . " - " . $TerminalName;
if ($nCmd == "4000000")
{
// SMTP_SendMail(18471 /*[Email IPS an aag]*/ ,
// $emailHeader." Finger not recognized",
// $emailDebugBody . "
"
// . $ekeyStringHex . "
"
// . $ekeyString . "
");
}
else
{
//Alarm unscharf stellen!
setvalue (55493 /*[Zugang\AlarmLogik\AlarmArmed]*/, false);
//send email
SMTP_SendMail(18471 /*[Email IPS an AAG]*/ ,
$emailHeader,
$emailDebugBody . "
"
. $ekeyStringHex . "
"
. $ekeyString . "
");
//Gong läuten
FS20_SwitchMode(19035 /*[Sportzimmer\FS20 Gong]*/, true); //Gong läuten
}
// the next line executes a cmd that sends a MsgBox to select computers (HTPC, AAG laptop).
IPS_ExecuteEx ("C:\IP-Symcon\msg.exe", "aag /SERVER:xy.xy.xy.23 /TIME:15 ".$emailHeader, false, false, 2);
IPS_ExecuteEx ("C:\IP-Symcon\msg.exe", "aag /SERVER:xy.xy.xy.8 /TIME:15 ".$emailHeader, false, false, 2);
echo $strEvent;
function hextostr($x) {
$s='';
foreach(explode("
",trim(chunk_split($x,2))) as $h) $s.=chr(hexdec($h));
return($s);
}
function strtohex($x) {
$s='';
foreach(str_split($x) as $c) $s.=sprintf("%02X",ord($c));
return($s);
}
?>