Alarm Camera

Foscam on alert, protecting my home.

Dark night, wind howling blah blah.   Honestly it is not an alarm system, it is a joke mash up to keep people away from my front door.  Works pretty simply and is a great example of how all these hardware devices can communicate easily together.

Step 1. Motion is triggered by the Foscam camera.

Step 2. Foscam send the Pi a HTTP POST saying alarm=true.

Step 3. It gets crazy.  API call to EtherRain to start the zone closest to the door. Person at the door is now trapped in a flurry of rain behind them. There only choice is to huddle the door.

Step 4. Seizure time. Lights go into disco mode – flashing on and off at random intervals to disorient potential intruder.

Here is the code:

<?php
define("ZWAVE_HOST", "localhost");
define("ZWAVE_PORT", 6004);

function sendReceiveMessage($in)
{
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
return "ERROR: socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}

$result = socket_connect($socket, ZWAVE_HOST, ZWAVE_PORT);
if ($result === false) {
return "ERROR: socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
}
socket_write($socket, $in, strlen($in));
//TODO: should really change this to keep getting until \n
$data=socket_read($socket, 2048,PHP_NORMAL_READ );
socket_close($socket);
usleep(250); //this just makes it happy
return $data;
}

if ($_GET['alarm'] == true)
{
//Time to kick on the water.
echo file_get_contents('http://192.168.20.168/ergetcfg.cgi?lu=admin&lp=pw');
echo file_get_contents('http://192.168.20.168/result.cgi?xi=0:1:0:0:0:0:0:0:0');

//Let's get the alarm going

$msg[]="DEVICE~6~255~Binary Switch";
$msg[]="DEVICE~5~0~Binary Switch";
$msg[]="DEVICE~5~255~Binary Switch";
$msg[]="DEVICE~6~0~Binary Switch";
$msg[]="DEVICE~6~255~Binary Switch";
$msg[]="DEVICE~6~0~Binary Switch";
$msg[]="DEVICE~5~0~Binary Switch";
$msg[]="DEVICE~6~255~Binary Switch";
$msg[]="DEVICE~6~0~Binary Switch";
$msg[]="DEVICE~5~255~Binary Switch";
$msg[]="DEVICE~6~255~Binary Switch";

for($i=0;$i<count($msg);$i++)
{
echo sendReceiveMessage($msg[$i]), "\n\n";
sleep(mt_rand(0,3));

}

}

I will grab a video in the light tomorrow.


Leave a Reply