Moin,
wie schon per PN geschrieben habe ich leider momentan echt wenig Zeit, deshalb kann ich Dir leider nur ein paar Bröckchen hinwerfen weil ich selbst nicht mehr so ganz weiß wie ich es gemacht habe…
Ich hab ja auch nur die Richtung IPS=>Android (in meinem Falle Telefon) gebaut.
Dazu brauchst Du nur terRemote, Tasker wird dazu nicht benötigt. Auch Eventghost nicht.
Meine Socket-Konfig sieht so aus:
Das „sendData“-Script dort sieht so aus bei mir:
<?
//Fügen Sie hier Ihren Skriptquellcode ein
// This Script send events to any Eventghost compatible Client via RegisterVariable -> IPS_Client_Socket
// Outgoing Events are read from "BufferToSend" Variable. This works like a send Buffer
// You should use my "SendToDroid() function to write Commands to the Buffer.
// Register variable MUST be named: "regVarDataBuffer"
// If you want to communicate with Eventghost PC please read comment near line 80
// During communication idle and Client Socket is dissabled (Gray Icon), this improved stability and prevent from mess up logging
// If Client is not reachable (Cleint Software Down) ClintSocket become Red Icon, this is cleard after first succesfull Event transfer.
// It works fine for me, but maybe your enviroment need any aditional error handling, check area around line 62
// The Script had been tested with: Eventghost for PC , Eventghost for Anroid, terRemote for Android
// rev 1.0 created by Bernhard Baptist 04.10.2012
// Change Configuration parameters if needed
$maxRetry = 5; // retries until buffer is cleared
$socketReadyDelay = 10; //delay between retries if socket not ready
$msgDelay = 10; // delay in sec until timeout and command re-send command
//-------------------------------------------------------------------------------------------
// Nothing to configure below this line
$Id_ClientSocket = IPS_GetParent($_IPS['SELF']);
$IDRegVar = @IPS_GetObjectIDByName("regVarDataBuffer", $Id_ClientSocket);
$IDBuffer = CreateVariableByName($Id_ClientSocket, 'BufferToSend', 3);
$IDerrorCount = CreateVariableByName($Id_ClientSocket, 'errorCount', 1);
Switch ($_IPS['SENDER'])
{
Case "Execute":
// reserved for debug
break;
Case "RunScript":
if (IPS_GetInstance($Id_ClientSocket)['InstanceStatus'] != 102) {// Check if Socket is Active
CSCK_SetOpen($Id_ClientSocket,true);
IPS_ApplyChanges($Id_ClientSocket);
if (IPS_GetInstance($Id_ClientSocket)['InstanceStatus'] != 102) {
IPS_SetScriptTimer($IPS_SELF, $socketReadyDelay); //arm Timer for retry
echo "Keine Verbindung zu ".IPS_GetName($Id_ClientSocket);
Return; // Stop in case Socket Open fail
}
}
RegVar_SendText($IDRegVar, "quintessence
\r"); // start handshake
IPS_SetScriptTimer($IPS_SELF, $msgDelay); //arm Timer for retry if Fail
break;
Case "TimerEvent":
IPS_SetScriptTimer($IPS_SELF, 0); //stop Timer
$errorCount=GetValue($IDerrorCount);
$errorCount=$errorCount+1;
if ($errorCount < $maxRetry) {
SetValue($IDerrorCount,$errorCount);
IPS_RunScript($_IPS['SELF']); // Run next try
}
else {
SetValue($IDerrorCount,0);
SetValueString($IDBuffer,"nothing to send");
// todo: add additional error processing there
}
break;
Case "RegisterVariable":
$data = $IPS_VALUE;
$data = trim($data);
Switch ($data) {
Case "accept": // ready to send data
$buffer=GetValueString($IDBuffer); //re-read in case modified meanwhile
$data_to_send= substr($buffer,0,strpos ($buffer ,"_+_"));
$posPayload = strpos ($data_to_send ,",");
if ($posPayload > 0){ // check if Payload should be added
$payload = "payload ".substr($data_to_send,$posPayload+1);
RegVar_SendText($IDRegVar,$payload."
"); //here the payload is sent
$data_to_send= substr($data_to_send,0,$posPayload);
RegVar_SendText($IDRegVar,$data_to_send."
\r"); //here the event is sent
}
else {
RegVar_SendText($IDRegVar,$data_to_send."
\r"); //here the event is sent
}
RegVar_SendText($IDRegVar, "close
\r");
// Eventghost PC does not send "close" so we cannot do proper handshake
// Remark next three lines in case your Client is Eventghost PC
// unremark this line: // sleep(1);
IPS_SetScriptTimer($IPS_SELF, $msgDelay); //arm Timer for retry if Fail
break;
case "close": // data successfull send
IPS_SetScriptTimer($IPS_SELF, 0); //Send Ok, stop Timer
SetValue($IDerrorCount,0);
CSCK_SetOpen($Id_ClientSocket,false);
$buffer=GetValueString($IDBuffer); //re-read in case modified meanwhile
if (substr_count ($buffer,"_+_")> 1) {
$pos_next =strpos ($buffer ,"_+_");
SetValueString($IDBuffer,substr($buffer,$pos_next+3,strlen($buffer))); //update
// sleep(1); // todo: find minimum delay
IPS_RunScript($_IPS['SELF']); // re-run to process next command
}
else{
SetValueString($IDBuffer,"nothing to send");
}
break;
case "declined": // any problem
// todo: add logic to recover,
CSCK_SetOpen($Id_ClientSocket,false);
IPS_SetScriptTimer($IPS_SELF, 1); //arm Timer for retry
break;
Default: // send Hash ti initiate handshake
$data .= ":";
$hash = md5($data);
$hash .= "
";
RegVar_SendText($IDRegVar, $hash);
Break;
}
}
// common helper Function
function CreateVariableByName($id, $name, $type)
{
global $IPS_SELF;
$vid = @IPS_GetVariableIDByName($name, $id);
if($vid===false) {
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
IPS_SetInfo($vid, "This Variable was created by Script #$IPS_SELF");
}
return $vid;
}
?>
Dann gibt es ein Script, dass von einem beliebigen Event getriggert wird:
<?
include_once "42551.ips.php";
//Fügen Sie hier Ihren Skriptquellcode ein
//CSCK_SendText(35650 /*[Client Socket - Grandstream Telefon CK]*/, "Beliebiger Datensatz"); //Sendet den Text "Beliebiger Datensatz" auf dem Client Socket mit der ID 12345
$CK_Telefon = 35650 /*[Client Socket - Grandstream Telefon CK]*/;
SendtoDroid($CK_Telefon,"Say,Bewegung vor der Haustuer erkannt");
?>
Das Script das in obigem Script included wird ist das Folgende:
<?
//Fügen Sie hier Ihren Skriptquellcode ein
// Call this function to add new command to ClientSocket message queue
// Args[$IDBuffer = ID of ClientSocket] [$new... command to be send]
function SendtoDroid($Id_ClientSocket,$new) {
$IDBuffer = @IPS_GetObjectIDByName("BufferToSend", $Id_ClientSocket);
$IDSendScript = @IPS_GetObjectIDByName("sendData", $Id_ClientSocket);
$maxQueueLenght = 10; // max Commands in Queue
$old = GetValueString($IDBuffer);
// cleanup queue if too much commands pending
if (substr_count ($old,"_+_") > $maxQueueLenght) {
$old ='nothing to send'; //todo: add error processing if required
}
if ($old == 'nothing to send') {
SetValue($IDBuffer,$new."_+_");
IPS_RunScript($IDSendScript);
}
else {
SetValue($IDBuffer,$old.$new."_+_");
}
}
?>
Ich glaube das ist „schon“ alles, damit IPS an das Android sendet.
Auf Android-Seite muss das terRemote entsprechend konfiguriert sein damit es auf Nachrichten reagiert - da kann ich gerade nicht gucken weil meine Frau telefoniert. :rolleyes:
Vlt. kommst Du damit ja schon einen Schritt weiter…
VG, Hocky