Storm
Storm

Reputation: 3252

Autodetect local server with ESP8266

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

Upvotes: 0

Views: 1094

Answers (1)

Mert Gülsoy
Mert Gülsoy

Reputation: 2929

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.

Upvotes: 1

Related Questions