<?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/refrigerator_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 "refrigerator is opened\r\n";
send_notification();
usleep(100000);
} else if($previous_status == 1 && $current_status == 0) { // if door is closed...
echo "refrigerator is closed\r\n";
}
$previous_status = $current_status;
}
?>
Comments
Please log in or sign up to comment.