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

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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法