Last active
August 29, 2015 14:07
-
-
Save onkeloki/0474c7f0fc14da186453 to your computer and use it in GitHub Desktop.
watch onkeloki.de
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
diese Klasse wird dazu verwendet | |
die alarmanlage an bzw aus zu schalten, | |
Ihr müsst die variablen $enablePin und $disablePin entpsrechend | |
eurer Konfiguration setzen | |
**/ | |
class Alarm | |
{ | |
static function enable() | |
{ | |
// GIPO Pin über dem das Relai zum anschalten der Alarmanlage geschaltet wird | |
$enablePin = 1337; | |
// SET PIN MODE | |
shell_exec("gpio -g mode " . $enablePin . " out"); | |
// BTN DOWN | |
shell_exec("gpio -g write " . $enablePin . " 0"); | |
// WAIT | |
sleep(1); | |
// BTN UP | |
shell_exec("gpio -g write " . $enablePin . " 1"); | |
} | |
static function disable() | |
{ | |
// GIPO Pin über dem das Relai zum anschalten der Alarmanlage geschaltet wird | |
$disablePin = 1338; | |
// SET PIN MODE | |
shell_exec("gpio -g mode " . $disablePin . " out"); | |
// BTN DOWN | |
shell_exec("gpio -g write " . $disablePin . " 0"); | |
// WAIT | |
sleep(1); | |
// BTN UP | |
shell_exec("gpio -g write " . $disablePin . " 1"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
include "GeoFancyData.php"; | |
include "IsHomeChecker.php"; | |
include "Alarm.php"; | |
/** BEIM ANKOMMEN */ | |
ignore_user_abort(true); | |
set_time_limit(0); | |
$geofancy = new GeoFancyData($_GET); | |
$checker = new isHomeChecker(); | |
// das device ist nicht bekannt es wird abgebrochen | |
$name = $checker->getNameByDevice($geofancy->getDevice()); | |
if (!$name) die("i do not know you"); | |
// geofancy gibt ein feedback | |
if($checker->deviceIsAtHome($geofancy->getDevice())){ | |
die($name." ist bereits zuhause"); | |
} | |
echo "Willkommen zuhause, " . $name; | |
// dem ishomechecker mitteilen dass das ankommende device nun zunause ist | |
$checker->setIsHome($geofancy->getDevice()); | |
/** DER CODE AB HIER | |
* wird nur ausgeführt wenn jemand erfolgreich angekommen ist | |
* hier könnte mann nun auch via pilight licht an und aus schalten und der gleichen | |
* | |
*/ | |
// die deaktivieren methode der Alarm klasse aufrufen | |
$alarm = new Alarm(); | |
$alarm->disable(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ein wrapper zum parsen der daten die geofancy schickt * | |
*/ | |
class GeoFancyData { | |
private $_device; | |
private $_id; | |
private $_latitude; | |
private $_longitude; | |
private $_trigger; | |
function __construct($data) { | |
$this->_device = @$data["device"]; | |
$this->_id = @$data["id"]; | |
$this->_latitude = @$data["latitude"]; | |
$this->_longitude = @$data["longitude"]; | |
$this->_trigger = @$data["trigger"]; | |
} | |
/** | |
* @param mixed $device | |
*/ | |
public function setDevice($device) { | |
$this->_device = $device; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getDevice() { | |
return $this->_device; | |
} | |
/** | |
* @param mixed $id | |
*/ | |
public function setId($id) { | |
$this->_id = $id; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getId() { | |
return $this->_id; | |
} | |
/** | |
* @param mixed $latitude | |
*/ | |
public function setLatitude($latitude) { | |
$this->_latitude = $latitude; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getLatitude() { | |
return $this->_latitude; | |
} | |
/** | |
* @param mixed $longitude | |
*/ | |
public function setLongitude($longitude) { | |
$this->_longitude = $longitude; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getLongitude() { | |
return $this->_longitude; | |
} | |
/** | |
* @param mixed $trigger | |
*/ | |
public function setTrigger($trigger) { | |
$this->_trigger = $trigger; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getTrigger() { | |
return $this->_trigger; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Diese Klasse wird Dafür verwendet zu checek ob jemand zuhause ist | |
für jedes device müsst ihr einen eintrag in dem Array _knownDevices pflegen | |
als wet könnt ihr den Namen der person setzen | |
die klasse erstellt eine Datei wenn "setIsHome" aufgerufen wird und löscht Sie wenn | |
"setIsAway" aufgerufen wird. dazu muss der ein ordner existieren der "status" heist | |
für diesen ordner müssen schreibrechte gewährt werden. | |
**/ | |
class isHomeChecker { | |
private $_knownDevices; | |
function __construct() { | |
$this->_knownDevices = array(); | |
$this->_knownDevices["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"] = "PERSON A"; | |
$this->_knownDevices["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"] = "PERSON B"; | |
} | |
function getNameByDevice($device) { | |
return @$this->_knownDevices[$device]; | |
} | |
function getFilename($device) { | |
return $this->getNameByDevice($device) . "_" . $device . ".txt"; | |
} | |
function deviceIsKnown($device) { | |
return array_key_exists($device, $this->_knownDevices); | |
} | |
function deviceIsAtHome($device) { | |
if (!$this->deviceIsKnown($device)) return; | |
return file_exists("status/" . $this->getFilename($device)); | |
} | |
function setIsHome($device) { | |
if (!$this->deviceIsKnown($device)) return; | |
$handle = fopen("status/" . $this->getFilename($device), "w"); | |
fwrite($handle, "1") or die("could not write"); | |
fclose($handle); | |
} | |
function howManyAreHome() { | |
$counter = 0; | |
$handle = opendir("status"); | |
while ($file = readdir($handle)) { | |
if ($file != "." && $file != "..") $counter++; | |
} | |
return $counter; | |
} | |
function nobodyHome() { | |
return $this->howManyAreHome() == 0; | |
} | |
function setIsAway($device) { | |
if (!$this->deviceIsKnown($device)) return; | |
@unlink("status/" . $this->getFilename($device)); | |
} | |
function geIshome($device) { | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include "GeoFancyData.php"; | |
include "IsHomeChecker.php"; | |
include "Alarm.php"; | |
/** BEIM GEHEN */ | |
ignore_user_abort(true); | |
set_time_limit(0); | |
$geofancy = new GeoFancyData($_GET); | |
$checker = new isHomeChecker(); | |
$name = $checker->getNameByDevice($geofancy->getDevice()); | |
if (!$name) die("i do not know you"); | |
// wenn jemand die Zone verlässt | |
$checker->setIsAway($geofancy->getDevice()); | |
echo "bye Bye, ".$name; | |
if ($checker->nobodyHome()) { | |
/** | |
* dieser code wird ausgeführt wenn, nachdem jemand die zone verlassen hat | |
* keiner mehr zuhause ist. | |
* hier könnte man auch das gesammte licht ausschalten und der gleichen | |
*/ | |
$alarm = new Alarm(); | |
$alarm->enable(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment