精神api响应成功但没有任何反应
I'm trying to implement milight api using http://www.limitlessled.com/dev.
I wrote a small php script which based on that. According to the documentation I always received the good response from my UDP request, all the request is successfull but nothing happens (Link light, siwth on/off etc..)
What I've done so far :
<?php
function getResponse($command)
{
$msg = vsprintf(str_repeat('%c', count($command)), $command);
$ip = "255.255.255.255";
$port = 5987;
$buf = null;
socket_sendto($sock, $msg, strlen($msg), 0, $ip, $port);
while (42) {
$ret = socket_recvfrom($sock, $buf, 22, 0, $ip, $port);
if ($ret === false) {
die(socket_strerror(socket_last_error()));
break;
} else {
break;
}
}
return $buf;
}
if (($sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) !== FALSE) {
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array(
"sec" => 5,
"usec" => 0
));
/** GET WIFI BRIDGE SESSION */
$command = array(
0x20,
0x00,
0x00,
0x00,
0x16,
0x02,
0x62,
0x3A,
0xD5,
0xED,
0xA3,
0x01,
0xAE,
0x08,
0x2D,
0x46,
0x61,
0x41,
0xA7,
0xF6,
0xDC,
0xAF,
0xD3,
0xE6,
0x00,
0x00,
0x1E
);
$buf = getResponse($command);
$checksum = dechex(0x3D + 0x00 + 0x00 + 0x08 + 0x00 + 0x00 + 0x00 + 0x00 + 0x00 + 0x01 + 0x00);
/** LINK COMMAND */
$command = array(
0x80,
0x00,
0x00,
0x00,
0x11,
bin2hex($buf[19]),
bin2hex($buf[20]),
0x00,
0x00,
0x00,
0x3D,
0x00,
0x00,
0x08,
0x00,
0x00,
0x00,
0x00,
0x00,
0x01,
0x00,
$checksum
);
$buf = getResponse($command);
for ($i = 0; $i < strlen($buf); $i++)
echo bin2hex($buf[$i]) . " ";
socket_close($sock);
}
?>
What I get is : 88 00 00 00 03 00 00 01.
I also try the LimitlessLED Wifi Bridge tool, what i can read from the log is :
Start Wifi Bridge Session...
Send UDP commands to 192.168.0.15 port 5987
Sent: 20 00 00 00 16 02 62 3A D5 ED A3 01 AE 08 2D 46 61 41 A7 F6 DC AF D3 E6 00 00 1E
Received: 28 00 00 00 11 00 02 F0 FE 6B 1E 26 62 72 1D E3 68 00 01 DA 01 00
LimitlessLEDWifiBridgeSessionID1 is DA
LimitlessLEDWifiBridgeSessionID2 is 01
IP Address is 192.168.0.15
MAC Address is FE:6B:1E:26:62:72
Sequence Number is 02
Checksum is 46
Sent: 80 00 00 00 11 DA 01 00 02 00 3D 00 00 08 00 00 00 00 00 01 00 46
Command SUCCESSFUL.
Received: 88 00 00 00 03 00 02 00
Command completed.
Everything seems to work fine, but nothing happens, I cannot control any light. I'm totaly stuck, does anyone have an ideas?
I'm using iBox2 as controller and an Mi-Light rgbw led bulb series.
Thank you
I figured out what was wrong.
First I noticed that request are not exactly the same between CW bulb and WW bulb. For example, the request you have to send to switch on the light with CW bulb is :
[ 0x31,0,0,0x08,0x04,0x01,0,0,0,zoneID ]
same request with WW bulb is :
[0x31, 0x00, 0x00, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, zoneID]
I also should not use "bin2hex" function but "unpack" instead.
I put an implementation of what I have done there : https://github.com/winosaure/MilightAPI
I hope it can help someone..