Multicasting WiFi tutorial (UPnP/SSDP) - Smart Home Hub

I’ve been working on a project for a while now that uses the FEZ feather to create a simple smart home hub, with the goal being to control lights and switches from the device and write my own scripts for automation. One day I’d like to connect to a smart assistant like alexa or google assistant, but for now just the light bulb connection is the goal.

I’m trying to connect to and control a GE Cync direct connect light bulb, meaning the bulb connects directly to the LAN. When I power it up, I can use Wireshark to see it’s DHCP/ARP broadcast. I can see the device’s IPv4 address and MAC address, but I don’t know exactly what protocol it uses to communicate. According to the internet, most devices like this use Universal Plug and Play (UPnP) and the Simple Search Discovery Protocol (SSDP) to easily initiate connections.

So far I’ve been able to establish a WiFi connection pretty easily following the WiFi tutorial, but for the life of me I can’t seem to understand the protocol behind multicasting, UPnP, and SSDP. A few forum posts say there would be some further tutorials on WiFi multicasting and I was wondering if there’s been any progress on this.

More so I was curious if anyone in the community has tried something like this and was able to get it to work. Here’s what I have/know so far, with a few examples of code below:

  • I started a multcast DNS process but I don’t know what that does
  • I know multicast IPs must be between 224.0.0.0 and 239.255.255.255
  • I am pretty sure multicast IPs between 239.255.0.0 and 239.255.255.255 are restricted to the local network?
  • I’ve selected a multicast IP at random of 239.255.36.36, put it through the MAC address generator from the tutorial and got 01-00-5e-7f-24-24
  • I know multicast MAC addresses should start with 01-00-5e
  • I was told SSDP is sent out on port 1900
  • I am making a connection with 239.255.255.250 but that was just one of the few addresses I saw on WireShark, not really sure what address to put here.
  • The format for the SSDP message was found at https://web.archive.org/web/20151107123618/http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v2.0.pdf
// --- Before connecting to WiFi ---
//Add the multicast MAC address and start a multicast DNS (TTL of 5 min)
Winc15x0Interface.AddMulticastMacAddress(new byte[] { 0x01, 0x00, 0x5E, 0x7F, 0x24, 0x24 });
MulticastDns.Start("GHI_Home_Server", TimeSpan.FromSeconds(300));



// --- Once connected to WiFi ---
//SSDP broadcast message
string header = "M-SEARCH * HTTP/1.1\r\n";
string host = $"HOST: 239.255.255.250:1900\r\n";
string man = "MAN: \"ssdp:discover\"\r\n";
string mx = "MX: 3\r\n";
string st = "ST: ssdp:all\r\n";

string requestMessage = header + host + man + mx + st + "\r\n";
byte[] dataToSend = Encoding.UTF8.GetBytes(requestMessage);

//Create the UDP socket and connect to the multicast IP/port - which IP?
_udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
_udpSocket.Connect(new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900));

//Send the SSDP request
byte[] receiveBytes = new byte[4096];
_udpSocket.Send(dataToSend);
_udpSocket.Receive(receiveBytes);

//No data is ever received
Debug.WriteLine(Encoding.UTF.GetString(receiveBytes));

In truth I don’t know what I’m doing, I found most of this information just scouring the internet. I’m not versed in multicasting and probably bit off more than I can chew, but I would like to learn. I also know there are options available on ESP32s using HomeKit, but I’ve become spoiled and pampered being able to write in C#/TinyCLR and really don’t want to have to revert back to C. If anyone has any tips/tricks/advice/questions I’d really appreciate the help with this project, and hopefully others can use the knowledge too.