parent
dc463b1968
commit
41538f48f3
3 changed files with 393 additions and 0 deletions
@ -0,0 +1,26 @@ |
||||
#!/bin/sh |
||||
|
||||
candle=$1 |
||||
|
||||
for i in 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F |
||||
do |
||||
result=$(gatttool -b "$candle" --char-read -a 0x00$i | sed 's_Characteristic value/descriptor: __g' | egrep '^[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s$') 2>/dev/null |
||||
if [ "$result" != "" ] |
||||
then |
||||
possible_color=$(echo -e "$possible_color\n0x00$i $result") |
||||
fi |
||||
result=$(gatttool -b "$candle" --char-read -a 0x00$i | sed 's_Characteristic value/descriptor: __g' | egrep '^[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s[0-9a-fA-F][0-9a-fA-F]\s$' 2>/dev/null) |
||||
if [ "$result" != "" ] |
||||
then |
||||
possible_effect=$(echo -e "$possible_effect\n0x00$i $result") |
||||
fi |
||||
done |
||||
|
||||
echo "" |
||||
echo "" |
||||
echo "Possible color handles found" |
||||
echo "$possible_color" |
||||
echo "" |
||||
echo "" |
||||
echo "Possible effect handles found" |
||||
echo "$possible_effect" |
@ -0,0 +1,227 @@ |
||||
<?php |
||||
|
||||
#### EDIT SETTINGS HERE #### |
||||
|
||||
$candles = array |
||||
( |
||||
array("xx:xx:xx:xx:xx:xx","0x0019","0x0017"), |
||||
array("xx:xx:xx:xx:xx:xx","0x0019","0x0017"), |
||||
array("xx:xx:xx:xx:xx:xx","0x0019","0x0017"), |
||||
array("xx:xx:xx:xx:xx:xx","0x001B","0x0019"), |
||||
); |
||||
|
||||
############################ |
||||
|
||||
$device = $_REQUEST['device']; |
||||
$setting = $_REQUEST['setting']; |
||||
$config = $_REQUEST['config']; |
||||
$refresh = $_REQUEST['refresh']; |
||||
|
||||
if ($config) { |
||||
$x = 1; |
||||
$return = []; |
||||
foreach ($candles as $n) |
||||
{ |
||||
$return["candle" . ($x++)] = array( 'id' => $n[0], 'color_handle' => $n[1], 'effect_handle' => $n[2] ); |
||||
} |
||||
echo json_encode( $return ); |
||||
|
||||
} |
||||
|
||||
if ($device && $refresh) { |
||||
|
||||
$devices = explode(",", $device); |
||||
|
||||
for ($x = 0; $x < count($candles); $x++) { |
||||
if ("$devices[0]" == "candle" . ($x+1)) |
||||
{ |
||||
$candle=$candles[$x][0]; |
||||
$color_handle=$candles[$x][1]; |
||||
$effect_handle=$candles[$x][2]; |
||||
} |
||||
} |
||||
|
||||
$output = shell_exec("gatttool -b $candle --char-read -a $effect_handle | sed 's_Characteristic value/descriptor: __g'"); |
||||
$effect_value = explode(" ", $output); |
||||
$effect_value = $effect_value[4] . $effect_value[5] . $effect_value[6] . $effect_value[7]; |
||||
$effect_color = explode(" ", $output); |
||||
$effect_color = $effect_color[0] . $effect_color[1] . $effect_color[2] . $effect_color[3]; |
||||
$output = shell_exec("gatttool -b $candle --char-read -a $color_handle | sed 's_Characteristic value/descriptor: __g'"); |
||||
$candle_color = trim(str_replace(" ", "", $output)); |
||||
|
||||
if (($candle_color === "00000000" && $effect_color === "00000000") || $effect_color === "00000000") { |
||||
//echo $device . " is off"; |
||||
$return = array( 'device' => $device, 'power' => 'off' ); |
||||
echo json_encode( $return ); |
||||
} |
||||
else { |
||||
//echo $device . " is on"; |
||||
$return = array( 'device' => $device, 'power' => 'on' ); |
||||
if ($candle_color !== "00000000") { |
||||
$return['color'] = $candle_color; |
||||
$return['effe'] = $effect_value; |
||||
$return['ecol'] = $effect_color; |
||||
} |
||||
echo json_encode( $return ); |
||||
} |
||||
} |
||||
|
||||
if ($device && $setting) { |
||||
|
||||
$devices = explode(",", $device); |
||||
$all_devices = []; |
||||
|
||||
for ($x = 0; $x < count($candles); $x++) { |
||||
for ($y = 0; $y < count($devices); $y++) { |
||||
if ("$devices[$y]" == "candle" . ($x+1)) |
||||
{ |
||||
array_push ( $all_devices, array($candles[$x][0],$candles[$x][1],$candles[$x][2]) ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
switch ($setting) { |
||||
case off: |
||||
$handle=$color_handle; |
||||
$color="0000000001000f0f"; |
||||
break; |
||||
case red: |
||||
$handle=$color_handle; |
||||
$color="00ff0000"; |
||||
break; |
||||
case green: |
||||
$handle=$color_handle; |
||||
$color="0000ff00"; |
||||
break; |
||||
case blue: |
||||
$handle=$color_handle; |
||||
$color="000000ff"; |
||||
break; |
||||
case white: |
||||
$handle=$color_handle; |
||||
$color="ff000000"; |
||||
break; |
||||
case yellow: |
||||
$handle=$color_handle; |
||||
$color="00ffff00"; |
||||
break; |
||||
case magenta: |
||||
$handle=$color_handle; |
||||
$color="00ff00ff"; |
||||
break; |
||||
case cyan: |
||||
$handle=$color_handle; |
||||
$color="0000ffff"; |
||||
break; |
||||
case flashred: |
||||
$handle=$effect_handle; |
||||
$color="00ff000000000f0f"; |
||||
break; |
||||
case flashgreen: |
||||
$handle=$effect_handle; |
||||
$color="0000ff0000000f0f"; |
||||
break; |
||||
case flashblue: |
||||
$handle=$effect_handle; |
||||
$color="000000ff00000f0f"; |
||||
break; |
||||
case flashwhite: |
||||
$handle=$effect_handle; |
||||
$color="ff00000000000f0f"; |
||||
break; |
||||
case flashyellow: |
||||
$handle=$effect_handle; |
||||
$color="00ffff0000000f0f"; |
||||
break; |
||||
case flashmagenta: |
||||
$handle=$effect_handle; |
||||
$color="00ff00ff00000f0f"; |
||||
break; |
||||
case flashcyan: |
||||
$handle=$effect_handle; |
||||
$color="0000ffff00000f0f"; |
||||
break; |
||||
case fadered: |
||||
$handle=$effect_handle; |
||||
$color="00ff000001000f0f"; |
||||
break; |
||||
case fadegreen: |
||||
$handle=$effect_handle; |
||||
$color="0000ff0001000f0f"; |
||||
break; |
||||
case fadeblue: |
||||
$handle=$effect_handle; |
||||
$color="000000ff01000f0f"; |
||||
break; |
||||
case fadewhite: |
||||
$handle=$effect_handle; |
||||
$color="ff00000001000f0f"; |
||||
break; |
||||
case fadeyellow: |
||||
$handle=$effect_handle; |
||||
$color="00ffff0001000f0f"; |
||||
break; |
||||
case fademagenta: |
||||
$handle=$effect_handle; |
||||
$color="00ff00ff01000f0f"; |
||||
break; |
||||
case fadecyan: |
||||
$handle=$effect_handle; |
||||
$color="0000ffff00000f0f"; |
||||
break; |
||||
case faderainbow: |
||||
$handle=$effect_handle; |
||||
$color="00ff000003000f0f"; |
||||
break; |
||||
case flashrainbow: |
||||
$handle=$effect_handle; |
||||
$color="00ff000002000f0f"; |
||||
break; |
||||
default: |
||||
if (strlen($setting) == 8) |
||||
{ |
||||
$handle=$color_handle; |
||||
$color=$setting; |
||||
} |
||||
elseif (strlen($setting) == 16) |
||||
{ |
||||
$handle=$effect_handle; |
||||
$color=$setting; |
||||
} |
||||
else |
||||
{ |
||||
// A valid option was not chosen" |
||||
} |
||||
} |
||||
|
||||
if ( $color === "00000000" || substr($color, 0, 8) === "00000000" ) |
||||
{ |
||||
$return = array( 'device' => $device, 'power' => 'off' ); |
||||
} else { |
||||
if (strlen($color) == 16) |
||||
{ |
||||
$return = array( 'device' => $device, 'power' => 'on', 'color' => substr($color, 0, 8), 'effect' => substr($color, 8, 8) ); |
||||
} |
||||
else if (strlen($color) == 8) { |
||||
$return = array( 'device' => $device, 'power' => 'on', 'color' => $color, 'effect' => '00000000' ); |
||||
} |
||||
else { |
||||
$return = array( 'error' => 'A valid option was not chosen' ); |
||||
} |
||||
} |
||||
echo json_encode( $return ); |
||||
|
||||
foreach ($all_devices as $x) |
||||
{ |
||||
//echo $x[0] . " " . $x[1] . " " . $x[2]; |
||||
if (strlen($color) == 16) |
||||
{ |
||||
$output = shell_exec("gatttool -b $x[0] --char-write -a $x[2] -n $color" ); |
||||
} else { |
||||
$output = shell_exec("gatttool -b $x[0] --char-write -a $x[1] -n $color" ); |
||||
} |
||||
usleep(500000); |
||||
} |
||||
} |
||||
|
||||
?> |
@ -0,0 +1,140 @@ |
||||
#!/bin/sh |
||||
|
||||
if [ "$1" = "candle1" ] |
||||
then |
||||
candle=xx:xx:xx:xx:xx:xx |
||||
color_handle="0x0019" |
||||
effect_handle="0x0017" |
||||
fi |
||||
if [ "$1" = "candle2" ] |
||||
then |
||||
candle=xx:xx:xx:xx:xx:xx |
||||
color_handle="0x0019" |
||||
effect_handle="0x0017" |
||||
fi |
||||
if [ "$1" = "candle3" ] |
||||
then |
||||
candle=xx:xx:xx:xx:xx:xx |
||||
color_handle="0x0019" |
||||
effect_handle="0x0017" |
||||
fi |
||||
if [ "$1" = "candle4" ] |
||||
then |
||||
candle=xx:xx:xx:xx:xx:xx |
||||
color_handle="0x001B" |
||||
effect_handle="0x0019" |
||||
fi |
||||
|
||||
if [ "$2" = "red" ] |
||||
then |
||||
handle=$color_handle |
||||
color="00ff0000" |
||||
elif [ "$2" = "blue" ] |
||||
then |
||||
handle=$color_handle |
||||
color="000000ff" |
||||
elif [ "$2" = "green" ] |
||||
then |
||||
handle=$color_handle |
||||
color="0000ff00" |
||||
elif [ "$2" = "magenta" ] |
||||
then |
||||
handle=$color_handle |
||||
color="00ff00ff" |
||||
elif [ "$2" = "yellow" ] |
||||
then |
||||
handle=$color_handle |
||||
color="00ffff00" |
||||
elif [ "$2" = "white" ] |
||||
then |
||||
handle=$color_handle |
||||
color="ff000000" |
||||
elif [ "$2" = "cyan" ] |
||||
then |
||||
handle=$color_handle |
||||
color="0000ffff" |
||||
elif [ "$2" = "off" ] |
||||
then |
||||
handle=$color_handle |
||||
color="00000000" |
||||
elif [ "$2" = "fadewhite" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="ff00000001000f0f" |
||||
elif [ "$2" = "fadered" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="00ff000001000f0f" |
||||
elif [ "$2" = "fadegreen" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="0000ff0001000f0f" |
||||
elif [ "$2" = "fadeblue" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="000000ff01000f0f" |
||||
elif [ "$2" = "fadeyellow" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="00ffff0001000f0f" |
||||
elif [ "$2" = "fademagenta" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="00ff00ff01000f0f" |
||||
elif [ "$2" = "fadecyan" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="0000ffff00000f0f" |
||||
elif [ "$2" = "flashwhite" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="ff00000000000f0f" |
||||
elif [ "$2" = "flashred" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="00ff000000000f0f" |
||||
elif [ "$2" = "flashgreen" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="0000ff0000000f0f" |
||||
elif [ "$2" = "flashblue" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="000000ff00000f0f" |
||||
elif [ "$2" = "flashyellow" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="00ffff0000000f0f" |
||||
elif [ "$2" = "flashmagenta" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="00ff00ff00000f0f" |
||||
elif [ "$2" = "flashcyan" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="0000ffff00000f0f" |
||||
elif [ "$2" = "flashrainbow" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="00ff000002000f0f" |
||||
elif [ "$2" = "faderainbow" ] |
||||
then |
||||
handle=$effect_handle |
||||
color="00ff000003000f0f" |
||||
else |
||||
if [ ${#2} = 8 ] |
||||
then |
||||
handle=$color_handle |
||||
color=$2 |
||||
elif [ ${#2} = 16 ] |
||||
then |
||||
handle=$effect_handle |
||||
color=$2 |
||||
else |
||||
echo "A valid option was not chosen" |
||||
fi |
||||
fi |
||||
|
||||
gatttool -b $candle --char-write -a $handle -n $color |
||||
gatttool -b $candle --char-write -a $handle -n $color |
||||
gatttool -b $candle --char-write -a $handle -n $color |
Loading…
Reference in new issue