CODE: LightwaveRF Control PHP Script

<?php
////////////////////////////////////////////////////////////////////////////////////////////////////
// PHP code for interfacing with the WiFi-Link from LightwaveRF.
// Written by Tinker Failure 2012. http://www.tinkerfailure.com
// Based on code by Steven, which can be found here: http://blog.networkedsolutions.co.uk/?p=149
//////////////////////////////////////////////////////////////////////////////////////////////////////
// This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 
// You may use and update this code as you see fit. But you must attribute it's source.
// Full details here: http://creativecommons.org/licenses/by-nc-sa/3.0/
////////////////////////////////////////////////////////////////////////////////////////////////////

function singleBroadcast($id_to_send, $node_to_send, $status_to_send)
    {
    $broadcastid = $id_to_send;
    $broadcastnode = $node_to_send;
    $broadcaststatus = $status_to_send;
    $broadcast_string = $code . ",!" . $broadcastid . $broadcastnode . $broadcaststatus . "|";
    $port = 9760;
    $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
    socket_sendto($sock, $broadcast_string, strlen($broadcast_string), 0, '255.255.255.255', $port);
    socket_close($sock);
    }

function multiBroadcast($id_to_send, $status_to_send)
    {
    $broadcastid = $id_to_send;
    $broadcaststatus = $status_to_send;
    $broadcast_string = $code . ",!" . $broadcastid .$broadcaststatus . "|";
    $port = 9760;
    $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
    socket_sendto($sock, $broadcast_string, strlen($broadcast_string), 0, '255.255.255.255', $port);
    socket_close($sock);
    }

function statecontrol($state_to_convert)
    {
        if ($state_to_convert == "on")
        {
            $devicestatus = "F1";
        }
        else if ($state_to_convert == "off")
        {
            $devicestatus = "F0";
        }
        else if ($state_to_convert == "offALL")
        {
            $devicestatus = "Fa";
        }
        else if ($state_to_convert == "mood01")
        {
            $devicestatus = "FmP1";
        }
        else if ($state_to_convert == "mood02")
        {
            $devicestatus = "FmP2";
        }                
        else if ($state_to_convert == "mood03")
        {
            $devicestatus = "FmP3";
        }
        else if ($state_to_convert == "1")
        {
            $devicestatus = "FdP1";
        }
        else if ($state_to_convert >= "2")
        {
            $devicestatus = "FdP" . ROUND($state * 0.32);
        }
    return $devicestatus;
    }

$code = "000";
$room = $_GET["room"];
$device = $_GET["device"];
$state = $_GET["state"];

if (!isset($room)) die("No Room Set?");
if (!isset($device)) die("No Device Set?");
if (!isset($state)) die("No State Set?");

switch ($room)

{
case all:

            if ($device == "all")
            {
                $id = "R1";
                $status= statecontrol($state);
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R2";
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R3";
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R4";
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R5";
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R6";
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R7";
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R8";
                multiBroadcast($id, $status);
            }
            elseif ($device == "ground")
            {
                $id = "R1";
                $status= statecontrol($state);
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R2";
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R8";
                multiBroadcast($id, $status);
            }
            elseif ($device == "first")
            {
                $id = "R3";
                $status= statecontrol($state);
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R4";
                multiBroadcast($id, $status);
            }
            elseif ($device == "second")
            {
                $id = "R5";
                $status= statecontrol($state);
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R6";
                multiBroadcast($id, $status);
                sleep(1);
                $id = "R7";
                multiBroadcast($id, $status);
            }            

    break;

case dining:

    $id = "R1";
            if ($device == "downlighters")
            {
                $node = "D1";
                $status= statecontrol($state);
            }
            elseif ($device == "ceiling")
            {
                $node = "D2";
                $status= statecontrol($state);
            }
            elseif ($device == "undercabinet")
            {
                $node = "D3";
                $status= statecontrol($state);
            }
            elseif ($device == "tablelamp")
            {
                $node = "D4";
                $status= statecontrol($state);
            }
        elseif ($device == "floorlamp")
            {
                $node = "D5";
                $status= statecontrol($state);
            }
            elseif ($device == "null")
            {
                $node = "D6";
                $status= statecontrol($state);
            }
    singleBroadcast($id, $node, $status);
      break;

case halls:

    $id = "R2";
            if ($device == "dev1")
            {
                $node = "D1";
                $status= statecontrol($state);
            }
            elseif ($device == "dev2")
            {
                $node = "D2";
                $status= statecontrol($state);
            }
            elseif ($device == "dev3")
            {
                $node = "D3";
                $status= statecontrol($state);
            }
            elseif ($device == "dev4")
            {
                $node = "D4";
                $status= statecontrol($state);
            }
            elseif ($device == "dev5")
            {
                $node = "D5";
                $status= statecontrol($state);
            }
            elseif ($device == "dev6")
            {
                $node = "D6";
                $status= statecontrol($state);
            }
    singleBroadcast($id, $node, $status);
      break;

case living:

    $id = "R3";
            if ($device == "dev1")
            {
                $node = "D1";
                $status= statecontrol($state);
            }
            elseif ($device == "dev2")
            {
                $node = "D2";
                $status= statecontrol($state);
            }
            elseif ($device == "dev3")
            {
                $node = "D3";
                $status= statecontrol($state);
            }
            elseif ($device == "dev4")
            {
                $node = "D4";
                $status= statecontrol($state);
            }
            elseif ($device == "dev5")
            {
                $node = "D5";
                $status= statecontrol($state);
            }
            elseif ($device == "dev6")
            {
                $node = "D6";
                $status= statecontrol($state);
            }
    singleBroadcast($id, $node, $status);
      break;

case masterbed:

    $id = "R4";
            if ($device == "dev1")
            {
                $node = "D1";
                $status= statecontrol($state);
            }
            elseif ($device == "dev2")
            {
                $node = "D2";
                $status= statecontrol($state);
            }
            elseif ($device == "dev3")
            {
                $node = "D3";
                $status= statecontrol($state);
            }
            elseif ($device == "dev4")
            {
                $node = "D4";
                $status= statecontrol($state);
            }
            elseif ($device == "dev5")
            {
                $node = "D5";
                $status= statecontrol($state);
            }
            elseif ($device == "dev6")
            {
                $node = "D6";
                $status= statecontrol($state);
            }
    singleBroadcast($id, $node, $status);
      break;

case 2ndbed:

    $id = "R5";
            if ($device == "dev1")
            {
                $node = "D1";
                $status= statecontrol($state);
            }
            elseif ($device == "dev2")
            {
                $node = "D2";
                $status= statecontrol($state);
            }
            elseif ($device == "dev3")
            {
                $node = "D3";
                $status= statecontrol($state);
            }
            elseif ($device == "dev4")
            {
                $node = "D4";
                $status= statecontrol($state);
            }
            elseif ($device == "dev5")
            {
                $node = "D5";
                $status= statecontrol($state);
            }
            elseif ($device == "dev6")
            {
                $node = "D6";
                $status= statecontrol($state);
            }
    singleBroadcast($id, $node, $status);
    break;

case 3rdbed:

    $id = "R6";
            if ($device == "dev1")
            {
                $node = "D1";
                $status= statecontrol($state);
            }
            elseif ($device == "dev2")
            {
                $node = "D2";
                $status= statecontrol($state);
            }
            elseif ($device == "dev3")
            {
                $node = "D3";
                $status= statecontrol($state);
            }
            elseif ($device == "dev4")
            {
                $node = "D4";
                $status= statecontrol($state);
            }
            elseif ($device == "dev5")
            {
                $node = "D5";
                $status= statecontrol($state);
            }
            elseif ($device == "dev6")
            {
                $node = "D6";
                $status= statecontrol($state);
            }
    singleBroadcast($id, $node, $status);
    break;

case 4thbed:

    $id = "R7";
            if ($device == "dev1")
            {
                $node = "D1";
                $status= statecontrol($state);
            }
            elseif ($device == "dev2")
            {
                $node = "D2";
                $status= statecontrol($state);
            }
            elseif ($device == "dev3")
            {
                $node = "D3";
                $status= statecontrol($state);
            }
            elseif ($device == "dev4")
            {
                $node = "D4";
                $status= statecontrol($state);
            }
            elseif ($device == "dev5")
            {
                $node = "D5";
                $status= statecontrol($state);
            }
            elseif ($device == "dev6")
            {
                $node = "D6";
                $status= statecontrol($state);
            }
    singleBroadcast($id, $node, $status);
      break;

case misc:

    $id = "R8";
            if ($device == "patiolights")
            {
                $node = "D1";
                $status= statecontrol($state);
            }
            elseif ($device == "gardenlights")
            {
                $node = "D2";
                $status= statecontrol($state);
            }
            elseif ($device == "irrigation")
            {
                $node = "D3";
                $status= statecontrol($state);
            }
            elseif ($device == "dev4")
            {
                $node = "D4";
                $status= statecontrol($state);
            }
            elseif ($device == "1stbathroom")
            {
                $node = "D5";
                $status= statecontrol($state);
            }
            elseif ($device == "2ndbathroom")
            {
                $node = "D6";
                $status= statecontrol($state);
            }
    singleBroadcast($id, $node, $status);
      break;

default:
    echo "No Room Found";
}
/*
echo "<p>$id</p>";
echo "<p>$node</p>";
echo "<p>$status</p>";
*/
?>