-2

I searched how to configure a DHCP server on ESP32 Arduino to distribute addresses for clients that connect to my ESP32 access point, but unfortunately I did not get any source code for that.

Any help?

1 Answer 1

3

As long as you use WiFi.softAP(), you do not need to explicitly configure a DHCP server on the ESP32. It will happen automatically - the library looks after it for you.

Here is a minimal example, where - in addition to setting the ESP32 up as an access point - a TCP server is also started on port 80.

WiFiServer server(80);

static const char *ap_ssid = "ESP32-001";
static const char *ap_pass = "temp_pass";

void setup() {
  Serial.begin(115200);

  WiFi.softAP(ap_ssid, ap_pass);
  Serial.print("Access point running. IP address: ");
  Serial.print(WiFi.softAPIP());
  Serial.println("");

  server.begin();
}

void loop() {
  WiFiClient client = server.available();

  if (client) {
    String client_ip = client.remoteIP().toString();
    Serial.print("Client connected. IP address = ");
    Serial.print(client_ip);
    Serial.println("");
    client.println("Hello ...");
    client.stop();
  }
}

I have attached the serial output in a screenshot below. Notice the

dhcps: send_offer>>udp_sendto result 0

message.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for reply ... but i need to add specific and unique IP addresses to my clients.
Please do a fast search, they are a lot of tutorials on how to do this, even in stackoverflow itself: randomnerdtutorials.com/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.