================================================================================= BELOW IS THE PHP SCRIPT THAT RECEIVES THE JSON FROM MICROCONTROLLER AND SENDS TEXT MESSAGES TO THE HOME OWNER(S) USING THEIR WIRELESS PHONE PROVIDER MMS SERVICE. THIS IS MADE FOR THE ELECTRIC IMP CODE. ALTERATIONS NEEDED IF YOU ARE USING ESP8266. Note: This script now sends back a requested sleep time (in seconds) as a response to the imp when the imp sends the prox switch sensor status. The imp can then sleep for 14 hours, overnight to save battery power. Otherwise during the day, it will wake up every 5 minutes and report the sensor status. 18){ $status="54000"; } if(date("G")>=0 && date("G")<10){ $status="54000"; } // Unpack the JSON array foreach ($data as $key=>$value) { if($key=="apikey"){$apikey=$value;} if($key=="mail"){$mail=$value;} } // Check the API key and only process if equal if($apikey == $myApikey){ // This part writes to a text file. // The time now and the unixtime is used this for another imp that changes colors if // it determines that the imp is operating OK, deep sleeping, or frozen (dead). $fname="lastupdate.txt"; $now = date("m-d-Y h:i:s a"); $unixtime = time(); $string = $now."|".$unixtime; $fx = fopen($fname, 'w') or die("can't open file"); fwrite($fx, $string); fclose($fx); $data=file("statusflag.txt"); $check=$data[0]; if($mail=="yes"){ if(date("G")>1 && date("G")<23 && $check<2){ $user="You have mail in your box!"; $filename="statusflag.txt"; $check=2; $fh = fopen($filename, 'w') or die("can't open file"); fwrite($fh, $check); fclose($fh); // Define your cell phone provider mms or txt email parameters $recipient = "5075551234@mms.att.net"; // @txt.att.net // @mms.att.net // $recipient = "5075551234@mms.att.net"; $subject = "Mail In Mailbox!"; $message = "Mail In Mailbox!"; $email = "noreply@yoursite.com"; $extraheaders = "From: $email\nReply-To: $email\n\n"; if (mail($recipient, $subject, $message, $extraheaders)){ //echo "email sent."; } else{ //echo "email did not send for some reason."; } } } if($mail=="no"){ if(date("G")>1 && date("G")<23 && $check>1){ $user="Mail has been removed."; $filename="statusflag.txt"; $check=1; $fh = fopen($filename, 'w') or die("can't open file"); fwrite($fh, $check); fclose($fh); // Define your cell phone provider mms or txt email parameters $recipient = "5075551234@mms.att.net"; // $recipient = "5075551234@mms.att.net"; $subject = "Mail Removed."; $message = "Mail Removed."; $email = "noreply@yoursite.com"; $extraheaders = "From: $email\nReply-To: $email\n\n"; if (mail($recipient, $subject, $message, $extraheaders)){ //echo "email sent."; } else{ //echo "email did not send for some reason."; } } } echo $status; }// end; if apikey matches else{ // api does not match, redirect to some other page. header('Location: https://www.yoursite.com/'); exit; } ?>