<?php require 'config.php'; if ( !isset($_REQUEST['color']) ) exit(); $hex = $_REQUEST['color']; $command = 0x01; $target = LEDTARGETID; $unique = mt_rand(1, 2000000000); $red = hexdec(substr($hex, 0, 2)); $green = hexdec(substr($hex, 2, 2)); $blue = hexdec(substr($hex, 4, 2)); $target = ($target > 0 ) ? 2 ** ($target - 1) : 0; $data = pack("CQLLCCC", $command, $target, $unique, 1000, $red, $green, $blue); $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1); for ( $i=0; $i<3; $i++ ) { socket_sendto($sock, $data, strlen($data), 0, LEDADDRESS, 6565); if ( $i < 2 ) usleep(10000); } socket_close($sock); ?>