I've been programming a C web server from scratch as an interface for controlling ESP8266 WiFi modules that I plan to use to control appliances & lighting with relays. In an attempt to make a user-friendly interface, I hope to implement auto-device discovery in an attempt to make the experience more seamless. In what way should I approach this? Here is my initial concept:

  1. WiFi module connects to your network.
  2. Have it host a UDP server that will wait for packets on port X.
  3. Have main server use subnet mask to send a UDP packet to all IP addresses on port X containing a packet of data saying "Hey, I'm the main server!"
  4. The WiFi module will acknowledge this by sending an HTTP POST request to the main server saying "Hey, I'm a device with ID Y! Add me to your list!"
  5. At this point, WiFi module stops listening for UDP packets.
  6. Module sets up TCP server to listen for commands. Commands between main server and devices will happen over TCP.

Is there any flaws in my plan? What about IPv6 (if those devices even support it)?

  • Could you also put up a list of security measures preventing data alterations, fake identities and control theft?
    – Basilevs
    Aug 22, 2015 at 19:51

1 Answer 1


There are existing protocols for performing discovery of devices; it would be better to use one of these than roll your own. The leading competitors are mDNS (aka Bonjour) and SSDP (aka Universal Plug and Play). I'd suggest reading up on these, and then picking up one of the many open source implementations to start working from.

  • Better in what way? Faster? More reliable?
    – dylanweber
    Aug 22, 2015 at 17:19
  • More likely to work in a wider variety of scenarios. Supported by networking tools that can help debug issues. More efficient. Generally understood by network engineers who might have to work with it. Less likely to trigger a false positive on IDS.
    – Jules
    Aug 23, 2015 at 6:20
  • Due to the complexity of SSPD or mDNS, I might hold off on adding device discovery until I get my software functioning in the first place. Do you have any advice where I can get better documentation?
    – dylanweber
    Aug 23, 2015 at 6:23
  • The Stroika class library makes SSDP client and server protocols (not mDNS), and makes both sides of discovery easy (in C++) - github.com/SophistSolutions/Stroika/tree/V2.1-Release/Samples - see SSDPClient and SSDPServer samples. Jul 27, 2018 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.