Mittlerweile gibt es im Forum ja einige Geofency Beiträge.
Die neue Geofency Version (appstore: Geofency) läuft nun absolut stabil, genau und auch ohne den Akku zu schmälern.
Gefency kann bestimmte URLs aufrufen, nachdem das IPHONE einen bestimmten Ort verlassen oder betreten hat.
Meine IPS Lösung hier:
[ol]
[li]Neuen Ordner webfront\user\geofency
[/li][li]index.php rein -fertig
[/li][li]settings.ips.php wird benötigt: (siehe hier:http://www.ip-symcon.de/forum/threads/20529-Script-(Klasse)-um-dauerhaft-Variablen-bzw-Arrays-zu-speichern?highlight=settings.ips.php)
[/li][/ol]
INDEX.PHP
<?php
// Geofency IPS Script für IP-Symcon
include "../../../scripts/settings.ips.php"; // ggf. Pfad anpassen (Siehe http://www.ip-symcon.de/forum/threads/20529)
$CONF["logfile"] = "./geofency.log"; // Pfad zum schreiben von LogFiles
$CONF["AUTH_USER"] = ""; // Derzeit nicht unterstützt bzw. beta.
$CONF["AUTH_PW"] = ""; //
$CONF["ScriptID"] = 58228; // Script ID oder auch andere OBjektID unter der die Variablen in IPS erzeugt werden.
$CONF["CreateLocationVars"] = true; // erzeuge Variable mit Positionsinfo unterhalb ID (s.o.) (MultiVar beachten!)
$CONF["MultiVar"] = false; // wenn true, wird pro Lokation eine Bool-Variable angelegt, sonst eine String mit Position
$CONF["AllowedDevices"] = Array("IphoneMax","IphoneMoritz"); // List of allowed Devices
$CONF["PosUnknown"] = "unbekannt"; // text for unknown Positoin (set when leaving)
$CONF["debug"] = true; // schreibt Logs (s.o.)
$set = new Settings;
$testmode = (@$_GET["test"] == "1")? true : false;
logentry("NEW REQUEST -------------------------------------------------------------");
if($CONF["debug"]){
logentry("Writing Debug Log entries:");
file_put_contents("./dbg.log", date('Y-m-d H:i:s')." NEW Action: ---------------------------
", FILE_APPEND);
file_put_contents("./dbg.log", "SERVER:
".print_r($_SERVER,true)."
", FILE_APPEND);
file_put_contents("./dbg.log", "GET:
".print_r($_GET,true)."
", FILE_APPEND);
file_put_contents("./dbg.log", "POST:
".print_r($_POST,true)."
", FILE_APPEND);
}
//Prüfen, ob Authentifizierung
if(!empty($CONF["AUTH_USER"])){
logentry("Authentication active");
if (empty($_SERVER['PHP_AUTH_USER'])) {
logentry("ERROR: Client does not send basic auth user - requesting authentication.");
header('WWW-Authenticate: Basic realm="Geofency Submit"');
header('HTTP/1.0 401 Unauthorized');
echo '<h1>Not Authorized</h2>';
die;
} elseif( ($_SERVER['PHP_AUTH_USER'] == $CONF["AUTH_USER"]) &&
($_SERVER['PHP_AUTH_PW'] == $CONF["AUTH_PW"]) ) {
logentry("Authentication successfull. Continue...");
// Alles passt - nichts weiter tun.
} else {
logentry("ERROR: Wrong authentication credentials. EXIT.");
header('WWW-Authenticate: Basic realm="Geofency Submit"');
header('HTTP/1.0 401 Unauthorized');
echo '<h1>Not Authorized</h2>';
die;
}
}
$a_track = $set->getValue("TRACKING", $CONF["ScriptID"]);
// Ein paar Prüfungen
if((!stristr($_SERVER["HTTP_USER_AGENT"],"Geofency")) && (!$testmode) ){
logentry("Wrong Client submitted. EXIT.");
header("Status: 403");
die("WRONG CLIENT");
}
// Check if Device is sent and correct
if(!$testmode){
if (isset($_GET["device"])) {
$t_device = $_GET["device"];
logentry("Recieved GET Device: $t_device");
} else {
logentry("ERROR. No Device is submitted.");
header("Status: 403");
die("No Device given");
}
} else {
$t_device = "Test";
logentry("Testmode Active. Test Device set.");
}
// Check Allowed Device
if(!in_array($t_device, $CONF["AllowedDevices"]) && ($t_device != "Test")){
logentry("ERROR: Device not allowed: $t_device");
header("Status: 403");
die("Device Not Allowed");
}
if($testmode){
$t_date = "2013-12-04T12:14:37Z";
$t_entry = (@"" == "1")? true : false;
$t_location = "Aesculap";
$t_locationID = "5C780537-21E6-41CB-ABFE-5A260AAD4BB3";
$t_long = 1.1111 ;
$t_lat = 2.2222 ;
} else {
$t_date = @$_POST["date"];
$t_entry = (@$_POST["entry"] == "1")? true : false;
$t_location = @$_POST["name"];
$t_locationID = @$_POST["id"];
$t_long = @$_POST["longitude"];
$t_lat = @$_POST["latitude"];
logentry("Recieved data: Date: $t_date, Entry: $t_entry, Location: $t_location, LocationID: $t_locationID, Long: $t_long, Lat: $t_lat");
}
// IPS Array schreiben
$a_track[$t_device] = Array("update" => time(), "date" => $t_date, "entry" => $t_entry, "location" => $t_location, "locationID" => $t_locationID, "longitude" => $t_long, "latitude" => $t_lat);
$set->setValue("TRACKING", $a_track, $CONF["ScriptID"]);
logentry("Settings DB updated.");
if($CONF["CreateLocationVars"] && (!empty($t_location))){
if($CONF["MultiVar"] == true){
logentry("Creating IPS Variable $t_location");
$id = CreateVariableByName($CONF["ScriptID"],$t_device." - ".utf8_decode($t_location) ,0);
setValue($id, $t_entry);
logentry("Value set to: $t_entry");
} else {
logentry("Creating IPS Location String Variable $t_device");
$id = CreateVariableByName($CONF["ScriptID"], $t_device, 3); //typ Sring
$position = ($t_entry)? trim(utf8_decode($t_location)) : $CONF["PosUnknown"];
setValue($id, $position);
logentry("$t_device Value set to: ".$position);
}
}
// Create Log String
$lgw = date('Y-m-d H:i:s') . ", ActionDate: ".$t_date.", Device: ".$t_device.", Location: ". $t_location . ", LocationID: ".$t_locationID.", Entry: ".$t_entry.", Longitude: ".$t_long.", Latitude: ".$t_lat."
";
logentry("Writing log entry: $lgw");
if(!empty($CONF["logfile"]))file_put_contents($CONF["logfile"], $lgw, FILE_APPEND);
logentry("SUCESS.");
echo "SUCCESS";
function logentry($msg = ""){
global $CONF;
if($CONF["debug"])file_put_contents("./dbg.log", date('Y-m-d H:i:s').": ".$msg."
", FILE_APPEND);
}
function CreateVariableByName($id, $name, $type, $profile = "")
{
# type: 0=boolean, 1 = integer, 2 = float, 3 = string;
global $_IPS;
$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']);
if($profile !== "") { IPS_SetVariableCustomProfile($vid, $profile); }
}
return $vid;
}
?>
in der Geofency App im IPhone gibt man dann folgendes beim Webhook einer Lokation an:
Event-URL Einstellung ->
Mitteilung bei Eintritt - AN
URL http://mydynhost.irgendwas.com:8080/user/geofency/?device=IphoneMax
Mitteilung bei Austritt - AN
URL http://mydynhost.irgendwas.com:8080/user/geofency/?device=IphoneMax
Fertig.
Und so sieht das dann in IPS aus:
Hier mit $CONF[„MultiVar“] = false (also Eine Variable pro Gerät mit Inhalt Position)
Ein Ereignis mit bedingung = zuhause bedeutet dann den start des scriptes Alarmanlage ausschalten.
Dh. komme ich in den Radius meines Hauses, wird die Alarmanlage deaktiviert
Das ganze Script kann man noch kann man noch etwas schützen dh. Kennwort etc. damit kein böswilliger es aufruft oder noch Zusatzdaten abfragen etc.
Falls es Probleme gibt, kann man auch mal in das Log einsicht nehmen:
gefency.log
oder
dbg.log (wenn aktiviert)