Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Code copied from http://www.everyhue.com/vanilla/discussion/comment/1052#Comment_1052
- $HUE_BRIDGE_ADRESS = 'address';
- $HUE_API_KEY = 'key';
- $url = ''.$HUE_BRIDGE_ADRESS.'/api/'.$HUE_API_KEY.'/lights';
- $bulbs = $_GET["bulb"];
- $bulblist = explode(',', $bulbs);
- foreach($bulblist as $bulb)
- {
- $previousState[$bulb] = getState($bulb);
- $newState = createData();
- $response = sendData($newState, $bulb);
- echo $response;
- }
- if ($blinktime = $_GET["blinktime"]){
- sleep($blinktime);
- foreach($bulblist as $bulb)
- {
- print_r($previousState[$bulb]);
- $response = sendData($previousState[$bulb], $bulb);
- echo $response;
- }
- }
- function getState($bulb){
- global $url;
- echo(''.$url.'/'.$bulb.'');
- $cf = curl_init(''.$url.'/'.$bulb.'');
- curl_setopt($cf, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($cf, CURLOPT_CUSTOMREQUEST, "GET");
- $response = curl_exec($cf);
- $lightstate = json_decode($response);
- if(!$response) {
- return false;
- }
- return $lightstate->state;
- }
- function createData(){
- if (isset($_GET['hue'])) $arrData['hue'] = (int)$_GET['hue'];
- else $arrData['hue'] = 100;
- if (isset($_GET['sat'])) $arrData['sat'] = (int)$_GET['sat'];
- else $arrData['sat'] = 254;
- if (isset($_GET['trans'])) $arrData['transitiontime'] = (int)$_GET['trans'];
- else $arrData['transitiontime'] = 10;
- if (isset($_GET['bri'])) $arrData['bri'] = (int)$_GET['bri'];
- else $arrData['bri'] = 240;
- if (isset($_GET['on'])) $arrData['on'] = (bool)$_GET['on'];
- else $arrData['on'] = true;
- return $arrData;
- }
- function sendData($data, $bulb){
- global $url;
- $ch = curl_init(''.$url.'/'.$bulb.'/state');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
- $response1 = curl_exec($ch);
- if(!$response1) {
- return false;
- }
- return response1;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment