0
votes

I have an ESP8266 module (particularly, Cactus Micro r2), which is able to connect to local network and then communicate with my local server via HTTP protocol. However, I have to provide the network SSID, password and the IP address of my server.

Is is possible for the ESP module to send a HTTP broadcast to the whole network with a particular header? And then, the server recognizing the header would respond, thus its IP address would be detected automatically? If not with HTTP, is it achievable with UDP? And is there a communication pattern for the client and server to discover each other?

The only solution (or rather a work-around) I have invented so far, is to iterate through the whole address range of a local subnet (which is usually 192.168.1.1-192.168.1.254) and try to initiate communication. However, this is extremely slow (if the server's IP address is in the upper half of the range). Plus, it will not work on 10.0.0.0 network (not to mention pure IPv6 networks...).

1
You need a DNS server to resolve name -> IP address. And of course, the server needs to be registered on the DNS. You could of course cheat and keep a record of the "last known address", and then start from that address next time. But DNS is the "right" solution. - Mats Petersson
That is even worse :D Is there, at least, the option to get all used IP addresses? Something like the 'arp -a' command in Windows command prompt? This would significantly reduce the number of iterated IP addresses... - Storm
arp -a just tracks what IP/mac addresses has talked to your machine (or your machine has talked to). If it doesn't "know" the server, then it probably hasn't talked to it either. - Mats Petersson
Yes, but the list of other machines can be filled by broadcasting the ping (or pinging the whole local network via 192.168.1.255)... So, could a system like that be simulated? - Storm
Well, that's more or less the same thing isn't it. What is the ACTUAL problem you are trying to solve? The problem has been solved by inventing DNS, so you're obviously trying to solve that problem in a different way, which typically means "you're doing it wrong". - Mats Petersson

1 Answers

1
votes

If you want your esp to find a dedicated server in any private network without requiring DNS and other setup this can be an answer:

  1. On the server side, implement a udp broadcast. This broadcasts the connection information of itself between some intervals (e.g. 2 sec). This is like wifi beaconing (or bluetooth advertising).
  2. On the esp side esp must know ssid. Then connect to the network. Start listening the broadcast port for a spesific message.
  3. Upon receiving the message, parse it and verify (authenticate etc.) then get the parameters from the message, which shows the server.
  4. Finally use the parameters to communicate with the server and turn off the broadcast listener.