Skip to content

Static IP of ESP32 in AP mode (AP+STA) has different value for clients (incremented by one) #4749

@RafigRzayev

Description

@RafigRzayev

I am using ESP32 as an access point, and set its IP to a predefined static value through softAPConfig(). Clients connect to ESP32 AP without problem. However, later when clients send HTTP requests, the requests don't get transmitted because the IP detected on client is invalid.

After checking ESP32 network parameters both on mobile phones and PC, it was visible that the IP address of network is different from the one we have originally set in the ESP32. Its value is incremented by one.

For example, static IP is 100.100.100.100,

  • Client detects the IP as 100.100.100.101, sends the request, and fails
  • Client manually sends the request to 100.100.100.100, success

The screenshot below shows the network information for ESP32 AP with static IP setting of 192, 168, 1, 160. IP4 addresses don't match.
Capture

You can observe the behaviour with the sketch below:

#include "WiFi.h"

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.print("Setting AP (Access Point)…");
  WiFi.mode(WIFI_AP_STA);  // AP + STA required because of wifi scan during AP
  const char* ssid = "MyESP32";
  const char* password = "abcdefghijk";
  if (!WiFi.softAP(ssid, password)) {
    Serial.println("AP Failed");
    return;
  }
  delay(2000);
  // Set static IP
  IPAddress AP_LOCAL_IP(192, 168, 1, 160);
  IPAddress AP_GATEWAY_IP(192, 168, 1, 4);
  IPAddress AP_NETWORK_MASK(255, 255, 255, 0);
  if (!WiFi.softAPConfig(AP_LOCAL_IP, AP_GATEWAY_IP, AP_NETWORK_MASK)) {
    Serial.println("AP Config Failed");
    return;
  }
  // Show the local IP
  Serial.print("AP IP address: ");
  IPAddress IP = WiFi.softAPIP();
  Serial.println(IP);
}

void loop() {
  // put your main code here, to run repeatedly:

}

Am I doing something wrong or is it normal behavior?

Edit: I noticed the same behavior even if no static IP is assigned, with default IP generation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions