Trying to use C# to connect to my light bulb

Hi guys

Today I tried to write e very simple c# script just to see if I could contact my yeelight bulb, but I cannot recieve answer, maybe I didn’t quite get how c# multicasting should be done, can you help ?

Thanks

  IPAddress multicastaddress = IPAddress.Parse("239.255.255.250");
        UdpClient udpclient = new UdpClient();
        udpclient.JoinMulticastGroup(multicastaddress);
        IPEndPoint remoteep = new IPEndPoint(multicastaddress, 1982);
        string ssdpMessage = "M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1982\r\nMAN: \"ssdp:discover\"\r\nST: wifi_bulb";

        Console.WriteLine(ssdpMessage);
        
        byte[] buffer = Encoding.ASCII.GetBytes(ssdpMessage);
        udpclient.Send(buffer, buffer.Length, remoteep);

        IPEndPoint AnyEndPoint = new IPEndPoint(IPAddress.Any, 0);

        while (true)
        {
            Byte[] data = udpclient.Receive(ref AnyEndPoint);
            string strData = Encoding.ASCII.GetString(data);
            Console.WriteLine(strData);
        }

Let us try your code and provide some update.

Could you put you full project code here? let me try it

Thank you very much, you can just copy paste this code on a new c# console project in the main it should work.

Thank Ricky , you can just copy paste this code on a new c# console project in the main it should run , regardless I will upload mine tonight :).

Hi Hitomi, I use your code and it works well.
Did you open developer mode in App setting? This is what needs to be done before using the Yeelight open API.

Hi Ricky , I indeed activated developer mode, thanks for testing my code and confirming it works !

On my side I don’t seem to receive any answer.

It could be caused by your router. If you are using OpenWrt, you need to turn on one option. http://forum.yeelight.com/t/python/69/8