DHCP Server in STA+AP mode · Issue #7880 · esp8266/Arduino (original) (raw)

Basic Infos

Platform

Settings in IDE

Problem Description

The module operates in STA+AP mode.
The station connects to the router. 2 clients are connected to the software access point: another esp8266 and a smartphone (android).

When the first client connects, the DHCP server assigns it the address 192.168.4.100.
If the second client connects in the near future (3-5 minutes), it will be assigned the address 192.168.4.101.
If the second client disconnects and 10-15 minutes pass between reconnection, the second client will be assigned the address 192.168.4.100.
The same situation will happen if time passes between the connections of the first and second clients (10-15 minutes), then the second client will be assigned the address 192.168.4.100.

This behavior occurs only if the station is connected to the router, if the router is turned off, or the module is in AP mode, then the DHCP server assigns correct addresses to clients.

If one of the clients connected to the access point is a laptop (Windows), then the assignment of addresses to new clients occurs correctly, but after disconnecting the laptop, the same addresses are assigned again (when reconnecting).

MCVE Sketch

#include <arduino.h> #include <ESP8266WiFi.h> #include <ESP8266WiFiAP.h> #include <Wire.h>

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

WiFi.mode(WIFI_STA);
WiFi.begin("ssid", "superMegaPassword");

while (WiFi.status() != WL_CONNECTED) 
{
    delay(1000);
}

IPAddress apIP(192, 168, 4, 1);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("tstESP_AP", "0123456789");

}

void ShowClients() { unsigned char number_client; struct station_info *stat_info;

struct ip4_addr *IPaddress; IPAddress address; int cnt=1;

number_client = wifi_softap_get_station_num(); stat_info = wifi_softap_get_station_info();

Serial.print("Connected clients: "); Serial.println(number_client);

while (stat_info != NULL) { IPaddress = &stat_info->ip; address = IPaddress->addr;

  Serial.print(cnt);
  Serial.print(": IP: ");
  Serial.print((address));
  Serial.print(" MAC: ");

  uint8_t *p = stat_info->bssid;
  Serial.printf("%02X:%02X:%02X:%02X:%02X:%02X", p[0], p[1], p[2], p[3], p[4], p[5]);

  stat_info = STAILQ_NEXT(stat_info, next);
  cnt++;
  Serial.println();

} }

void loop() { ShowClients(); delay(5000); }

Debug Messages

Client 1 connected
1-2 minutes passed
Client 2 connected

Connected clients: 2
1: IP: 192.168.4.100 MAC: F4:**:**:**:**:03
2: IP: 192.168.4.101 MAC: 80:**:**:**:**:03

Client 1 connected
10-15 minutes passed
Client 2 connected

Connected clients: 2
1: IP: 192.168.4.100 MAC: F4:**:**:**:**:03
2: IP: 192.168.4.100 MAC: 80:**:**:**:**:03

(See previous debug post)
Client 3 connected (Windows laptop)

Connected clients: 3
1: IP: 192.168.4.100 MAC: F4:**:**:**:**:03
2: IP: 192.168.4.100 MAC: 80:**:**:**:**:03
3: IP: 192.168.4.101 MAC: AC:**:**:**:**:5F

(See previous debug post)
android smartphone disconnected and connected again

Connected clients: 3
1: IP: 192.168.4.100 MAC: F4:**:**:**:**:03
2: IP: 192.168.4.101 MAC: AC:**:**:**:**:5F
3: IP: 192.168.4.102 MAC: 80:**:**:**:**:03

(See previous debug post)
the laptop disconnected, and then (within a few seconds) the android smartphone reconnected

Connected clients: 2
1: IP: 192.168.4.100 MAC: F4:**:**:**:**:03
2: IP: 192.168.4.100 MAC: 80:**:**:**:**:03