HAI > Ardunio > PHP > Email > SMS

The Goal:

Receive alerts on event based actions (i.e. garage door opens)

The Problem:

HAI makes you purchase their Windows Home Server to receive email or text message notifications. This would be fine if I had a use for the rest of the plugin. Which focuses on web based control, video recorder, lighting & audio control.

WL3 for Windows Home Server Add-in

The Solution:

Send a message from HAI to Arduino via Serial then have Arduino call a webpage that will notify me.

The HAI Omni LTe allows for 5 serial outputs and can speak several different languages in addition to HAI proprietary languages including X10, UPB, ZigBee. The HAI Pro-link language is very simple serial interface that does not require authentication like the HAI Omni-Link to interface with, as it does not require authentication to use like the Omni-Link. For my purpose I don’t need the additional features of the Omni-Link that include the ability to arm and disarm the panel. The serial connection is RS232 and unfortunately it is not native to Arduino which uses UART for serial communication. I found a RS232 to UART converter that will be the middle man on eBay for about $7 bucks shipped.

RS232 to UART

HAI Automation Code

WHEN Garage Door Sensor NOT READY
     THEN SEND Garage is Opening OUT SERIAL 2

‘Garage is Opening’ is actually the name of the message variable, I have the content of this variable defined as “[GarageOpening].” When this code executes it will send this string to Arduino. I used brackets for a specific reason. Since HAI is going to be sending multiple messages to Arduino. Arduino has to know when to “be ready” to start buffering the serial data. I do this by looking out for a ‘[‘ and then close the buffer when it reaches ‘]’. Then I take that message and send a GET REQUEST to a webpage that will take the GET variable, process the data and send me a message. The message is an email to my Verizon vtext address (10digitcellphonenumber@vtext.com) that comes to my phone as a text message.

Before the garage door is more than half way up my phone has received a text message: “HAI: Garage Door Opening.”

Update: Verizon vtext Emails Blocked

You can see the code below.

Arduino Code

#include <Ethernet.h>
#include <SPI.h>
#include <SoftwareSerial.h>

//Local IP Address
byte ip[] = { 10, 10, 0, 30 };
byte subnet[] = { 255, 255, 255, 0 };
byte gateway[] = { 10, 10, 0, 1 };
byte ddns[] = { 10, 10, 0, 1 };
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

//Server where PHP Message Parser resides
IPAddress server(174,120,97,7);
char serverName[] = "ambrosedigiorgio.com";

EthernetClient client;

//Key
String controlKey = "0000000";

//Serial
SoftwareSerial portOne(7,8);

//Variables
boolean buffer = false;
String message = "";

void setup()
{
  Serial.begin(9600);
  portOne.begin(9600);

  Serial.println("Serial Ready!");

  Ethernet.begin(mac, ip, ddns, gateway, subnet);

  if (client.connect(serverName, 80)) {
    Serial.println("Ethernet Ready!");
    client.println("GET http://[path to message parser]index.php?key=" + controlKey + "&attribute=ArduinoBoot HTTP/1.0");
    client.println();
  }
  else
  {
     Serial.println("Ethernet NOT Ready!"); 
  }
  
  
}

void loop()
{
 
  portOne.listen();
 
  if (client.available()) {
    char c = client.read();
      Serial.print(c);
  }

  if (!client.connected()) 
  {
    client.stop();
  }
  
  while (portOne.available() > 0) {
    char inByte = portOne.read();
    
    if(inByte == '[') //start of message
    {
       buffer = true;
    }
    
    if(inByte == ']') //end of message
    {
       buffer = false;
       
       Serial.println();
       Serial.print("Got Message: ");
       Serial.println(message);
       
       action(message);
       message = "";
    }
    
    if(buffer == true && inByte != '[') //append characters
    {
        message += inByte;
    }
  }
}

void action(String msg)
{
  if (client.connect(serverName, 80)) {
    client.println("GET http://[path to message parser]index.php?key=" + controlKey + "&attribute=" + msg + " HTTP/1.0");
    client.println();
  }
}

PHP Message Relay

$controlKey = "0000000";
$getKey = $_GET['key'];
$attribute = $_GET['attribute'];
$value = $_GET['value'];

if($controlKey == $getKey) //authentication
{
	switch($attribute)
	{
		case "ArduinoBoot":
			$status = "Arduino Online";
			break;
		case "GarageOpening":
			$status = "Garage Door is Opening";
			break;
		case "GarageClosing":
			$status = "Garage Door is Closing";
			break;
		default:
			$status = $attribute;
	}
	
	//import Swift Mailer Library http://swiftmailer.org/
	require_once('../swift/swift_required.php');

	$transport = Swift_MailTransport::newInstance();
		
	$mailer = Swift_Mailer::newInstance($transport);
	$message = Swift_Message::newInstance()
		//->setSubject("Panel Update:")
		->setFrom(array('arduino@ambrosedigiorgio.com' => 'Arduino'))
		->setReplyTo("arduino@ambrosedigiorgio.com")
		->setTo(array('0123456789@vtext.com' => 'Ambrose Di Giorgio'))
		->setBody("HAI: " . $status, 'text/html');
	
	$result = $mailer->send($message);
	echo "Status: " . $status;
}
else
{
	echo "404";
}
  • Enrico Camilloni

    hello, basically you read with arduino the serial port and when arduino reads the “keywords” (like [GarageOpening] in your example) you can do some actions with arduino. is it right?