diff --git a/config.php b/config.php index 5b5c41f..ebb1eb1 100644 --- a/config.php +++ b/config.php @@ -61,7 +61,7 @@ $buffer_length = strlen("PLUM 8888 12345678-90ab-cdef-1234-567890abcdef 8443");//Set the buffer length to what we expect to receive from a lightpad. -$amqp_port = 2708; +$stream_port = 2708; //-----------------------Plum Website Config-----------------------// $user_agent_header = 'User-Agent';//User agent header. @@ -75,4 +75,4 @@ $plum_room_url = $plum_url.'getRoom'; //Url of plum to obtain array of room info. $plum_logical_load_url = $plum_url.'getLogicalLoad'; //Url of plum to obtain array of logical load info. $plum_lightpad_url = $plum_url.'getLightpad'; //Url of plum to obtain array of lightpad info. -?> \ No newline at end of file +?> diff --git a/plum_lightpad_stream.php b/plum_lightpad_stream.php index a04233c..ae09ace 100644 --- a/plum_lightpad_stream.php +++ b/plum_lightpad_stream.php @@ -17,7 +17,7 @@ function lightpad_motion($lightpad_information, $signal)//Triggered when motion is detected by a switch. { echo "Motion Detected: [".$lightpad_information['house_name']." - ".$lightpad_information['room_name']." - ".$lightpad_information['logical_load_name']."]\n"; - + //Example - If motion detected on downstairs or theatre switches, toggle the lights. //if($lightpad_information['logical_load_name'] == 'Downstairs' || $lightpad_information['logical_load_name'] == 'Theatre') //{ @@ -49,7 +49,7 @@ function lightpad_power($lightpad_information, $watts)//Triggered when the watt foreach($lightpad_config as $lightpad_id => $lightpad_info)//For every lightpad in the config. { $sockets[$lightpad_id] = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);//Create a new TCP socket. - + if ($sockets[$lightpad_id] === false)//Check to make sure it was created correctly. { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";//Spit out an error if not. @@ -58,8 +58,8 @@ function lightpad_power($lightpad_information, $watts)//Triggered when the watt { echo "Socket For: ".$lightpad_info->ip." Created.\n";//Or claim success. } - - $connect_result = socket_connect($sockets[$lightpad_id], $lightpad_info->ip, $amqp_port);//Connect the socket to the amqp port. + + $connect_result = socket_connect($sockets[$lightpad_id], $lightpad_info->ip, $stream_port);//Connect the socket to the stream port. if ($connect_result === false)//Check to make sure it connected. { echo "socket_connect() failed.\nReason: ($connect_result) " . socket_strerror(socket_last_error($socket)) . "\n";//Spit out an error if not. @@ -68,7 +68,7 @@ function lightpad_power($lightpad_information, $watts)//Triggered when the watt { echo "Socket For: ".$lightpad_info->ip." Connected.\n";//Or claim success. } - + socket_set_nonblock($sockets[$lightpad_id]);//Set non blocking of the socket so we can read without waiting when something does change. } @@ -80,7 +80,7 @@ function lightpad_power($lightpad_information, $watts)//Triggered when the watt $except = null; $timeout = null; $buffer = 2048;//Leave room for a lot of messages, max is usually at most 3. - + if(socket_select($read, $write, $except, $timeout) > 0);//Monitor all the connections to lightpads and wait until one has sent us a message. { foreach($sockets as $lightpad_id => $socket)//Check every lightpad. @@ -89,11 +89,11 @@ function lightpad_power($lightpad_information, $watts)//Triggered when the watt if($message)//If there is a message... { $message = str_replace("\n", '', $message);//Remove newlines. - $message = str_replace("\r", '', $message);//Remove carriage returns. + $message = str_replace("\r", '', $message);//Remove carriage returns. $updates = explode(".", $message);//Set up an array and split on . array_pop($updates);//Get rid of the last empty entry in the array. $lightpad_information = lightpad_information($lightpad_id);//Pull all the information for this lightpad from the config. - + foreach($updates as $key => $update)//For every message from the lightpad { $data = json_decode($update);//Turn it into an object. @@ -128,4 +128,4 @@ function lightpad_power($lightpad_information, $watts)//Triggered when the watt socket_close($socket); echo "OK.\n\n"; } -?> \ No newline at end of file +?>