-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add capability to have light static DHCP lease #5594
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
Conversation
Maybe small, but it's actually one of the things I wanted to look into at some point in the future for my own use case. @d-a-v assuming that lwip doesn't have this already buried behind some config macro or something, this might make a good proposal for them. In that case, the function name would need to change to follow lwip convention, though. |
I think it's a small change that could easily be part of lwip if they agree. Any suggestions about naming and where it should be exposed ? |
Your PR updates the espressif dhcpserver in lwIP-1.4. For historical reason, we try to not modify lwIP-v1.4 because espressif might change these source files anytime (last time was 1 year ago). dhcpserver in lwIP-v2 is an updated copy of dhcpserver from lwIP-v1.4 (the one you modified).
There is no dhcp server in upstream lwIP. |
Is it better if I put it in a new file tools/sdk/lwip2/builder/glue-lwip/esp-dhcplease.c? |
This one is ours, so not better.
|
Ok, so I'll update tools/sdk/lwip2/builder/glue-lwip/esp-dhcpserver.c |
af2bbcc
to
5d9bfe3
Compare
You should PR on lwip2 repo first edit:
Then press the PR button on github |
I tryed to do it in one time but no way... |
other minor fixes
#5613 is proposed as PR in return, with your add-on,
|
Done |
@SmartBlug Can you please give more details?
|
From my side: I assume that after having the ESP reboot the client connected to the softap get different IP addresses? |
Your right, this not clear enough. Ex: you specify Static IP address for your DHCP Server :
If unknown device is connected, it will be 192.168.0.102 |
Nice explanation and use case. Please
Hint: before committing the example, use |
A question: WiFi.softAP() is called first, then the lease setup api is called. What happens if there are clients that connect in between? isn't that a race condition? |
I first started to specify mac and ip @ but it need more changes in the current code and also require more memory.
Adding IP @ need to change this logic (no pb) but also need to add IP @ in memory (then use more memory) That's the reason why I changed my mind and get back on just the mac @ ;-) |
You were right @devyte, call to I'll update the sample when I'll include the sample as suggested by @d-a-v. |
added ESP8266WiFi StaticLease sample
I found also a case where leases are reset when using WiFi.persistant. This is important that WiFi.persistent is set to false otherwise |
@d-a-v : Do I need to update something else or it's ok to validate and close this PR ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will merge asap
Hi. |
@mbm60 did you test the above code or the official staticlease.ino example? |
yes i tested libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino with version 2.5 and git version. |
Did you clear wifi settings? Use persistent(false)? You may be encountering the case described above. |
yes i used exactly above example, just add some debug code and persistent still false and erase all flash content before uploading. Platform
Settings in IDE
MCVE Sketch#include <lwip/init.h>
#if LWIP_VERSION_MAJOR == 1
void setup() {
Serial.begin(115200);
Serial.println("wifi_softap_add_dhcps_lease() is not implemented with lwIP-v1");
}
void loop() {
}
#else
#include <ESP8266WiFi.h>
const char *ssid = "ESPap";
const char *password = "thereisnospoon";
IPAddress apIP(192, 168, 0, 1);
void setup() {
struct station_info *stat_info;
String address;
uint8_t i;
uint8 mac_CAM[6] = { 0x00, 0x0C, 0x43, 0x01, 0x60, 0x15 };
uint8 mac_PC[6] = { 0xb4, 0x52, 0x7e, 0x9a, 0x19, 0xa5 };
Serial.begin(74880);
Serial.println();
Serial.println("Configuring access point...");
WiFi.persistent(false);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
wifi_softap_add_dhcps_lease(mac_CAM); // always 192.168.0.100
wifi_softap_add_dhcps_lease(mac_PC); // always 192.168.0.101
WiFi.softAP(ssid, password);
Serial.print("AP IP address: ");
Serial.println(WiFi.softAPIP());
Serial.println("HTTP server started");
while ( WiFi.softAPgetStationNum() == 0 ) {
delay ( 500 ); Serial.print ( "." );
}
stat_info = wifi_softap_get_station_info();
while (stat_info != NULL) {
address = IPAddress(stat_info->ip).toString();
Serial.print("client= ");
Serial.print(i);
Serial.print(" IP adress is = ");
Serial.print((address));
Serial.print(" Mac : ");
Serial.printf("%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(stat_info->bssid));
stat_info = STAILQ_NEXT(stat_info, next);
i++;
Serial.println();
}
}
void loop() {
}
#endif // lwIP-v2 Debug Messages
|
Please open a NEW issue. This is a PR that is already merged. |
ok |
This seems to be related to the comment I made on 17 Jan : |
Just add a small function that allow to have static lease for a specific mac when ESP8266 is used as AP.
This is really usefull to easily retrieve device content based on their IP.
Each time wifi_softap_add_dhcps_lease(mac) is called, it reserv the next IP address for this mac, starting to the first addr = dhcps_lease.start_ip.addr and with last possible allocation = dhcps_lease.end_ip.addr
Small feature but really usefull for my point of view