michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
412 stars 114 forks source link

Add MdnsBridgeLocator #203

Closed Indigo744 closed 4 years ago

Indigo744 commented 4 years ago

Continuing #198

The last one! The discovery using the M-DNS protocol MdnsBridgeLocator

I had some trouble making this one work, since the RFC are not that helpful sometimes. And there are 2 related RFC : the DNS one (specifiying the classic DNS request) and the M-DNS one specifying the difference.

Hopefully, with a bit of Wireshark spying I was able to figure it out.

After coding the new locator, it occurs to me that the working was almost identical to the SSDP one, with only a different multicast address, port and message.

Since I strongly believe in DRY code, I went ahead and merged the behavior in a new abstract class MUdpBasedBridgeLocator for locators based on UDP multicast discovery.

Hope you like it, feel free to comment / ask for modification.

Indigo744 commented 4 years ago

Ah and I forgot, but now SSDP/M-DNS will send multicast request every seconds until the timeout. It helps in case the bridge fails to see the first message for some reason.