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();
}
}