<?php
/*
Script (C) KixAss 2013 - pebble_tv@kixass.net

For use with PebbleUPC - Controling your Horizonbox from your wrist.
*/

function makeBuffer($data)
{
    
$data str_replace(" """$data);
    return 
hex2bin($data);
}

$localip $_GET["localip"];
if (empty(
$localip))
    exit(
"No local ip given");

$localport $_GET["localport"];
if (empty(
$localport))
    exit(
"No local port given");

$key $_GET["key"];
if (empty(
$key))
    exit(
"No key given");

if (
$sock fsockopen($localip$localport))
{
    
$data fgets($sock); // Get and return versionnumber
    
fwrite($sock$data);
    
usleep(500);

    
$data fgets($sock2);
    
fwrite($sockmakeBuffer("01")); // Send Ack
    
usleep(500);

    
$data fgets($sock4);
    
fwrite($sockmakeBuffer("01")); // Send Ack
    
usleep(500);

    
$data fgets($sock24);
    
fwrite($sockmakeBuffer("02 00 00 01 00 00 00 00")); // Send specifications
    
usleep(500);

    
fwrite($sockmakeBuffer("04 01 00 00 00 00 " $key)); // Turn key on
    
usleep(400);
    
fwrite($sockmakeBuffer("04 00 00 00 00 00 " $key)); // Turn key off

    
fclose($sock);
}
?>