diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp index cc5847dec..a424eece1 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp @@ -179,10 +179,8 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch * @param local_ip access point IP * @param gateway gateway IP * @param subnet subnet mask - * @param dhcp_start first IP assigned by DHCP - * @param dhcp_end last IP assigned by DHCP */ -bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_start, IPAddress dhcp_end) { +bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet) { DEBUG_WIFI("[APConfig] local_ip: %s gateway: %s subnet: %s\n", local_ip.toString().c_str(), gateway.toString().c_str(), subnet.toString().c_str()); if(!WiFi.enableAP(true)) { // enable AP failed @@ -206,52 +204,35 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA } struct dhcps_lease dhcp_lease; + IPAddress ip = local_ip; + ip[3] += 99; + dhcp_lease.start_ip.addr = static_cast(ip); + DEBUG_WIFI("[APConfig] DHCP IP start: %s\n", ip.toString().c_str()); - uint32_t net_addr = info.ip.addr & info.netmask.addr; - uint32_t bcast_addr = net_addr | !info.netmask.addr; - - // Assign user-supplied range, checking its validity - IPAddress ip = (static_cast(dhcp_start) & !info.netmask.addr) | net_addr; - - dhcp_lease.start_ip.addr = ip; - if(ip != net_addr && ip != bcast_addr && ip != info.ip.addr && ip != info.gw.addr) { - DEBUG_WIFI("[APConfig] DHCP IP start: %s\n", ip.toString().c_str()); - } else { - dhcp_lease.start_ip.addr=0; - } - - ip = (static_cast(dhcp_end) & !info.netmask.addr) | net_addr; + ip[3] += 100; dhcp_lease.end_ip.addr = static_cast(ip); - if(ip != net_addr && ip != bcast_addr && ip != info.ip.addr && ip != info.gw.addr) { - DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str()); - } else { - dhcp_lease.end_ip.addr=0; + DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str()); + + if(!wifi_softap_set_dhcps_lease(&dhcp_lease)) { + DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n"); + ret = false; } - if(dhcp_lease.start_ip.addr && dhcp_lease.end_ip.addr) { - if(!wifi_softap_set_dhcps_lease(&dhcp_lease)) { - DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n"); - ret = false; - } + // set lease time to 720min --> 12h + if(!wifi_softap_set_dhcps_lease_time(720)) { + DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_lease_time failed!\n"); + ret = false; + } - // set lease time to 720min --> 12h - if(!wifi_softap_set_dhcps_lease_time(720)) { - DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_lease_time failed!\n"); - ret = false; - } + uint8 mode = 1; + if(!wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode)) { + DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_offer_option failed!\n"); + ret = false; + } - uint8 mode = 1; - if(!wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode)) { - DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_offer_option failed!\n"); - ret = false; - } - - if(!wifi_softap_dhcps_start()) { - DEBUG_WIFI("[APConfig] wifi_softap_dhcps_start failed!\n"); - ret = false; - } - } else { - DEBUG_WIFI("[APConfig] DHCP daemon not started (range error or user request)\n"); + if(!wifi_softap_dhcps_start()) { + DEBUG_WIFI("[APConfig] wifi_softap_dhcps_start failed!\n"); + ret = false; } // check config @@ -273,25 +254,6 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA } -/** - * Configure access point - * @param local_ip access point IP - * @param gateway gateway IP - * @param subnet subnet mask - */ -bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet) { - IPAddress dhcp_start; - IPAddress dhcp_end; - - // calculate dhcp_start and DHCP_end as done in the old code - dhcp_start = local_ip; - dhcp_start[3] += 99; - dhcp_end = dhcp_start; - dhcp_end[3] += 100; - - softAPConfig(local_ip, gateway, subnet, dhcp_start, dhcp_end); -} - /** * Disconnect from the network (close AP) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiAP.h b/libraries/ESP8266WiFi/src/ESP8266WiFiAP.h index 0e734d9c8..fae8efd56 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiAP.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiAP.h @@ -37,7 +37,6 @@ class ESP8266WiFiAPClass { public: bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4); - bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_start, IPAddress dhcp_end); bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet); bool softAPdisconnect(bool wifioff = false);