Question

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)?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
scroll top