0
I'm trying to create android app which can control Yeelight wifi color bulb. I've written simple peace of code that connect to Yeelight but I'm really not sure what exactly I'm doing wrong. 

This code contain simple SSDP message which connect on 239.255.255.250:1982 port.

All the devices connected to same wifi (bulb and phone) I'm having D-Link DIR 600M router.

Exception : I'm getting connectiontimout exception. It doesn't matter how much time I set but this code will fail to connect after given time.

Apology for dirty code.

**Here is the code**

    public void connectDevice(){
        try {

            byte[] sendData;
            byte[] receiveData = new byte[1024];
            DatagramSocket clientSocket=null;

    /* Create the search request */
            String NL = "\r\n";
            StringBuilder mSearch = new StringBuilder();
            mSearch.append("M-SEARCH * HTTP/1.1").append(NL);
            mSearch.append("HOST: 239.255.255.250:1982").append(NL);
            mSearch.append("MAN: \"ssdp:discover\"").append(NL);
            mSearch.append("ST: wifi_bulb");
            try {

    /* Send the request */
                sendData = mSearch.toString().getBytes();
                DatagramPacket sendPacket = new DatagramPacket(
                        sendData, sendData.length, InetAddress.getByName("239.255.255.250"), 1982);
                clientSocket = new DatagramSocket();
                clientSocket.setSoTimeout(50000);
                clientSocket.send(sendPacket);

    /* Receive one response */

                DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
                clientSocket.receive(receivePacket);

            }
            catch (Exception e) {
                e.printStackTrace();
            }

            clientSocket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
  • Did you turn on 3rd party LAN control for the bulb inside official Yeelight app? – Pawel May 09 '18 at 17:46
  • No I didn't do it. And please let me know if it's absolute mandatory action to connect with yeelight color wifi bulb with 3rd party api and why? – Naveen Sharma May 10 '18 at 05:35
  • I tried connect with bulb after switch on the LAN control(bulb connected to office yeelight app) in this case I'm able to connect to bulb. But If I disconnect the bulb from official yeelight app and then try to connect to bulb with my 3rd party app I'm getting time out exception. Could you please let me know how can I keep LAN control enable always without connect to official yeelight app. – Naveen Sharma May 10 '18 at 16:25
  • Sadly Yeelight bulbs are proprietary devices and they just stop responding if you disable LAN control in the official app. How exactly do you disconnect from official app, do you unpair/reset them? I haven't encountered LAN control being automatically toggled off personally. – Pawel May 10 '18 at 18:42
  • I delete it from the offical app and try to connect with my 3rd party app. And I got timeout exception – Naveen Sharma May 10 '18 at 18:55
  • Tell me what happen if I connect the bulb , switch on the LAN control and delete the bulb. And now try to connect it from 3rd party app. I got timeout exception in this case. Have you ever experienced this? – Naveen Sharma May 10 '18 at 18:57
  • Looks like unpairing from the app forces LAN control off, not much You can do about it. – Pawel May 10 '18 at 19:02
  • If this is case. Everytime 3rd party try to connect to yeelight wifi bulb they have to make sure it's already connected to official yeelight app and LAN control in ON. Right? – Naveen Sharma May 10 '18 at 19:08
  • Yeah it's limitation put on by Xiaomi. – Pawel May 10 '18 at 19:24
  • Okay. I would like to thank you for your suggestions , they were really helpful. Thanks. – Naveen Sharma May 10 '18 at 19:26

0 Answers0