phpoc_man
Published

PHPoC - Notifying via Email When Water Is Leaked

Send email notification when water leak is detected.

BeginnerShowcase (no instructions)789
PHPoC - Notifying via Email When Water Is Leaked

Things used in this project

Hardware components

PHPoC Blue
PHPoC Blue
×1
SparkFun Water Sensor
×1
Jumper Wires
DIYables Jumper Wires
×1

Story

Read more

Schematics

wiring

Code

task0.php

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

include_once "/lib/sn_dns.php";
include_once "/lib/sn_esmtp.php";
include_once "/lib/sd_340.php";
function send_email()
{
	esmtp_account("xxxxxxx@gmail.com", "Water Sensor");
	esmtp_auth("xxxxxxx@gmail.com", "your_password");
	esmtp_msa("smtp.gmail.com", 465);

	$subject = "Water Leak";
	$message = "Water leak is deteated\r\n";

	$msg = esmtp_send("xxxxxxx@gmail.com", "to_name", $subject, $message);

	if($msg == "221")
		echo "send mail successful\r\n";
	else
		echo "send mail failed\r\n";
}

uio_setup(0, 0, "in");
$previous_value = 1;

while(1)
{
	$current_value = uio_in(0, 0);

	if($current_value == 0 && $previous_value == 1)
		send_email();

	$previous_value = $current_value;
	sleep(1);
}
?>

Credits

phpoc_man

phpoc_man

62 projects • 405 followers

Comments