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:
- WiFi module connects to your network.
- Have it host a UDP server that will wait for packets on port X.
- 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!"
- 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!"
- At this point, WiFi module stops listening for UDP packets.
- 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)?