phpoc_man
Published © GPL3+

PHPoC - Monitoring Door Open via Facebook Messenger

If door is opened, PHPoC sends a message to your Facebook Messenger.

BeginnerFull instructions provided1 hour1,380
PHPoC - Monitoring Door Open via Facebook Messenger

Things used in this project

Hardware components

PHPoC Blue
PHPoC Blue
×1
Door Sensor Magnetic Switch
DIYables Door Sensor Magnetic Switch
×1
Starter Kit
DIYables Starter Kit
×1

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Schematics

phpoc-wiring_gBawKJELB3.jpg

Code

task0.php

PHP
<?php

if(_SERVER("REQUEST_METHOD"))
	exit; // avoid php execution via http request

include_once "/lib/sn_http_b2.php";
include_once "/lib/sd_340.php";

define("IFTTT_WEBHOOKS_KEY", "xxxxxxxxxxxxxxxxxxxxxx"); // change your webhooks key here

function send_notification()
{

	$url = "https://maker.ifttt.com/trigger/door_open/with/key/" . IFTTT_WEBHOOKS_KEY;
	$resp_head = http_request("GET", $url, "");
	$resp_body = "";

	if($resp_head !== "")
		$rlen = http_read_sync($resp_body);

	http_close();

	echo "$resp_body\r\n";
}

uio_setup(0, 11, "in_pu");  // configuring pin 11 of the UIO 0 to input with pull-up

$previous_status = 1;

while(1)
{
	$current_status = uio_in(0, 11); ;

	if($previous_status == 0 && $current_status == 1) { // if door is opened...
		echo "door is opened\r\n";
		send_notification();
		usleep(100000);
	} else if($previous_status == 1 && $current_status == 0) { // if door is closed...
		echo "door is closed\r\n";
	}

	$previous_status = $current_status;
}
?>

Credits

phpoc_man

phpoc_man

62 projects • 407 followers

Comments