-
Notifications
You must be signed in to change notification settings - Fork 13.3k
DHCP Server in STA+AP mode #7880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is an interesting finding. |
Optimized the code. With the 2.7.4 release, the problem described in the first message still appears. MCVE Sketch#include <arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include "Ticker.h"
Ticker t;
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 EventCb(System_Event_t *evt)
{
switch (evt->event)
{
case EVENT_SOFTAPMODE_STACONNECTED:
case EVENT_SOFTAPMODE_STADISCONNECTED:
t.once_scheduled(3, ShowClients);
break;
}
}
void setup()
{
Serial.begin(115200);
wifi_set_event_handler_cb(EventCb);
WiFi.mode(WIFI_STA);
WiFi.begin("ssid", "superMegaPassword");
Serial.println("");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(1000);
}
Serial.println("");
IPAddress apIP(192, 168, 4, 1);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("tstESP_AP", "0123456789");
}
void loop()
{
} Did some experiments
struct dhcps_lease dhcp_lease;
IPAddress ip = local_ip;
ip [3] + = 99;
dhcp_lease.start_ip.addr = ip.v4 ();
ip [3] + = 100;
dhcp_lease.end_ip.addr = ip.v4 ();
if (! wifi_softap_set_dhcps_lease (& dhcp_lease))
Debug Messages
|
If you can't try the git version, there's the "stage" version in platformio, or an unofficial snapshot release for the arduino IDE. Both point to a recent version of git master. |
Installed Arduino Ide 1.8.13 Debug Messages
|
According to SoftAP code, it should indeed be .100+ |
@d-a-v And, this catches my eye:
I also saw problems disappear with debug options in #7795 (comment) |
@mhightower83 Your issue was forgotten - Thanks for the heads-up ! I tagged it |
softAPConfig returns true MCVE Sketch#include <arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
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 EventCb(System_Event_t *evt)
{
switch (evt->event)
{
case WIFI_EVENT_SOFTAPMODE_DISTRIBUTE_STA_IP:
case WIFI_EVENT_SOFTAPMODE_STADISCONNECTED:
ShowClients();
break;
default:
break;
}
}
void setup()
{
Serial.begin(115200);
wifi_set_event_handler_cb(EventCb);
WiFi.mode(WIFI_STA);
WiFi.begin("ssid", "superMegaPassword");
Serial.println("");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(1000);
}
Serial.println("");
IPAddress apIP(192, 168, 4, 1);
if (WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)))
Serial.println("softAPConfig: True");
else
Serial.println("softAPConfig: False");
if (WiFi.softAP("tstESP_AP", "0123456789"))
Serial.println("softAP: True");
else
Serial.println("softAP: False");
}
void loop()
{
} Debug Messages
|
@DedkovArtem Also when |
#define DHCPS_DEBUG 0 Debug Messages
#define DHCPS_DEBUG 0 Debug Messages
|
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
Debug Messages
Client 1 connected
1-2 minutes passed
Client 2 connected
Client 1 connected
10-15 minutes passed
Client 2 connected
(See previous debug post)
Client 3 connected (Windows laptop)
(See previous debug post)
android smartphone disconnected and connected again
(See previous debug post)
the laptop disconnected, and then (within a few seconds) the android smartphone reconnected
The text was updated successfully, but these errors were encountered: