Thing we needs
  • PHPoC Blue or Black
  • Water Sensor

Demonstration






How it works

The water sensor will switch LOW when water is detected.

By checking state of input pin, we can detect the present of water and then send email notification.



Wiring

Click image for larger version

Name:	20190620_131901.jpg
Views:	130
Size:	53.5 KB
ID:	1622



Code

PHP Code:
<?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("[email protected]""Water Sensor");
    
esmtp_auth("[email protected]""your_password");
    
esmtp_msa("smtp.gmail.com"465);

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

    
$msg esmtp_send("[email protected]""to_name"$subject$message);

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

uio_setup(00"in");
$previous_value 1;

while(
1)
{
    
$current_value uio_in(00);

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

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