Hier noch mal alle Befehle zum Ausprobieren wie diese in der
REST API angegeben sind.
$ip = "192.168.1.81";
$mac = "64002d00af2a";
$mystrominfo = myStrom_GetValues($ip, $mac);
var_dump($mystrominfo);
// Test
//ON
$result = myStrom_PowerOn($ip, $mac);
var_dump($result);
// OFF
$result = myStromPowerOff($ip, $mac);
var_dump($result);
// Toggle
$result = myStromToggle($ip, $mac);
var_dump($result);
// Dim To
$color = "00FF0000";
$ramptime = "1000";
$result = myStromDimTo($ip, $mac, $color, $ramptime);
var_dump($result);
// White
$result = myStromWhite($ip, $mac);
var_dump($result);
// Red
$result = myStromRed($ip, $mac);
var_dump($result);
// Green
$result = myStromGreen($ip, $mac);
var_dump($result);
// Blue
$result = myStromBlue($ip, $mac);
var_dump($result);
// HSV
$h = 0;
$s = 0;
$v = 100;
$result = myStromHSV($ip, $mac, $h, $s, $v);
var_dump($result);
function myStrom_GetValues($ip, $mac)
{
$URL = "http://".$ip."/api/v1/device/".$mac;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
return $result;
}
function myStrom_PowerOn($ip, $mac)
{
$command = "action=on";
$result = myStrom_Send($ip, $mac, $command);
return $result;
}
function myStromPowerOff($ip, $mac)
{
$command = "action=off";
$result = myStrom_Send($ip, $mac, $command);
return $result;
}
function myStromToggle($ip, $mac)
{
$command = "action=toggle";
$result = myStrom_Send($ip, $mac, $command);
return $result;
}
function myStromDimTo($ip, $mac, $color, $ramptime)
{
$command = "action=on&ramp=".$ramptime."&color=".$color;
$result = myStrom_Send($ip, $mac, $command);
return $result;
}
function myStromWhite($ip, $mac)
{
$color = "FF000000";
$command = "color=".$color;
$result = myStrom_Send($ip, $mac, $command);
return $result;
}
function myStromRed($ip, $mac)
{
$color = "00FF0000";
$command = "color=".$color;
$result = myStrom_Send($ip, $mac, $command);
return $result;
}
function myStromGreen($ip, $mac)
{
$color = "0000FF00";
$command = "color=".$color;
$result = myStrom_Send($ip, $mac, $command);
return $result;
}
function myStromBlue($ip, $mac)
{
$color = "000000FF";
$command = "color=".$color;
$result = myStrom_Send($ip, $mac, $command);
return $result;
}
function myStromHSV($ip, $mac, $h, $s, $v)
{
$command = "color=".$h.";".$s.";".$v;
$result = myStrom_Send($ip, $mac, $command);
return $result;
}
function myStrom_Send($ip, $mac, $command)
{
$URL = "http://".$ip."/api/v1/device/".$mac;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $command);
$result=curl_exec ($ch);
curl_close ($ch);
return $result;
}
?>
Neuen Kommentar hinzufügen