dongliming2416 2017-03-21 23:59
浏览 59
已采纳

精神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

  • 写回答

1条回答 默认 最新

  • dongmangji0950 2017-04-14 23:12
    关注

    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..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大