-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Setting DHCP IP-range start for softAP #6271
Comments
This does not look like something that should be fixed on the ESP32 SoftAP side. Why did the clients hold their lease if the AP was rebooted and they had to reconnect again? This does not sound at all OK and not how networking works. To "hold" a lease, a client must first tell the DHCP server that it intends to do so and the DHCP server needs to respond that it has accepted the same lease. |
@ch-fb @me-no-dev How to reproduce: I disconnect Win10 and reset AP (C3), at the same time. Keep ESP32 STA on. This is not easy to reproduce. I had to try it several times to see the issue in action.ESP32 STA Log (set Menu Option
|
A possible solution to this issue is to detect the STA_LOST_IP and restart WiFi STA. Example: // call back function when IP is Lost by Station -- needs to reconnect to AP
void WiFiStationLostIP(arduino_event_id_t event)
{
log_d("Enter into LOST IP Event Call Back...");
while (! WiFi.reconnect()) {
log_d("Trying to Reconnect due to STA__LOST_IP...");
delay(500); // wait a bit for the necessary processing
}
}
void setup()
{
Serial.begin(115200);
// Set a callback function when the event STA_LOST_IP happens
WiFi.onEvent(WiFiStationLostIP, ARDUINO_EVENT_WIFI_STA_LOST_IP);
Serial.println("STA_LOST_IP event callback is set.");
// Start WiFi in STA Mode
WiFi.begin(ssid, password);
Serial.println("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
} |
I tested the LOST IP EVENT callback and it works as expected, reconnecting the STA again when its IP is used by another device, right after AP reset/reboot. This is the STA log with the suggestion I made: There are two steps in the LOG:
|
Please let me know if this solution with WiFi Event Callback solves the issue. |
Hi, sorry for replying so late. Reboting an ESP32 is very fast, so it's AP is gone for just a very short time, too short for other STAs to even notice. And after the reboot, ESPs DHCP server does not know about them anymore. My workaround with cycling through different IP ranges works quite nicely in practice and would not mean much to be implemented in arduino-esp32. I don't know whether a DHCP server has the possibility to force all STAs to renew their leases. If so, this could be the solution, but that one is part of the SDK. |
@SuGlider Can you please take a look on last comment and validate if already merged PR fix this fully? Thanks! |
That's good news, thanks a lot
…On Fri, 13 May 2022, 03:05 Rodrigo Garcia, ***@***.***> wrote:
@ch-fb <https://github.com/ch-fb> - The PR #6731
<#6731> implements the
feature you have requested.
It shall be merged for the Arduino Core 2.0.4 future release, but you can
apply it to your project if you want to do so.
—
Reply to this email directly, view it on GitHub
<#6271 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVJ2D4XVZAAG26TM62TGRUTVJUM4JANCNFSM5OHOTXZQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Related area
WiFi softAP DHCP
Hardware specification
ESP32
Is your feature request related to a problem?
When several Wi-Fi stations are connected to an ESP's softAP and the ESP reboots, it can happen that some stations hold on to their old DHCP lease. However, the DHCP server does not know and re-assigns such still-in-use IP addresses. As a workaround for the problem, the DHCP server could use a different IP range after each restart (i.e. cycling through several ranges), but this requires the possibility of configuring the DHCP server.
Describe the solution you'd like
Possibility of configuring the DHCP server:
*) Adding IPAddress argument to softAPConfig:
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcpstart);
(can be an optional argument using a default value, or the current 3-argument version softAPConfig(local_ip,gateway,subnet) calls the extended 4-argument version)
*) This requires adding an argument to set_esp_interface_ip:
esp_err_t set_esp_interface_ip(esp_interface_t interface, IPAddress local_ip=IPAddress(), IPAddress gateway=IPAddress(), IPAddress subnet=IPAddress(), IPAddress dhcpstart=IPAddress());
An implementation could look like this:
dhcps_lease_t lease;
lease.enable = true;
lease.start_ip.addr = static_cast<uint32_t>(dhcpstart);
lease.end_ip.addr = static_cast<uint32_t>(dhcpstart) + (10 << 24);
instead of
lease.start_ip.addr = static_cast<uint32_t>(local_ip) + (1 << 24);
lease.end_ip.addr = static_cast<uint32_t>(local_ip) + (11 << 24);
This extension would help me (and probably some others) a lot.
Thanks for all your great work,
Christian
Describe alternatives you've considered
No response
Additional context
No response
I have checked existing list of Feature requests and the Contribution Guide
The text was updated successfully, but these errors were encountered: