Skip to content

Commit 13b8ff0

Browse files
committed
Make sure to call SDK functions to start and stop DHCP server
As noticed in esp8266#8582 (comment) Can't really use `server.begin()` and `server.end()` directly, only default static IP is applied to the interface since DHCP server is deemed 'running' (see `wifi_softap_dhcps_status()` return value)
1 parent 98c2837 commit 13b8ff0

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* psk, int channel,
167167
DEBUG_WIFI("[AP] softap config unchanged\n");
168168
}
169169

170-
auto& server = softAPDhcpServer();
171-
server.end();
170+
wifi_softap_dhcps_stop();
172171

173172
// check IP config
174173
struct ip_info ip;
@@ -179,17 +178,13 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* psk, int channel,
179178
IPAddress(192, 168, 4, 1),
180179
IPAddress(192, 168, 4, 1),
181180
IPAddress(255, 255, 255, 0));
182-
if(!ret) {
183-
DEBUG_WIFI("[AP] softAPConfig failed!\n");
184-
ret = false;
185-
}
186181
}
187182
} else {
188183
DEBUG_WIFI("[AP] wifi_get_ip_info failed!\n");
189184
ret = false;
190185
}
191186

192-
server.begin();
187+
wifi_softap_dhcps_start();
193188

194189
return ret;
195190
}
@@ -227,9 +222,10 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA
227222
info.gw.addr = gateway.v4();
228223
info.netmask.addr = subnet.v4();
229224

230-
auto& server = softAPDhcpServer();
231-
server.end();
232-
225+
// use SDK function for dhcps, not just server.begin()
226+
// setting info with static IPs will fail otherwise
227+
// (TODO: dhcps_flag seems to store 'SDK' DHCPs status)
228+
wifi_softap_dhcps_stop();
233229
if(!wifi_set_ip_info(SOFTAP_IF, &info)) {
234230
DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n");
235231
ret = false;
@@ -246,14 +242,17 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA
246242
dhcp_lease.end_ip.addr = ip.v4();
247243
DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str());
248244

245+
auto& server = softAPDhcpServer();
249246
if(!server.set_dhcps_lease(&dhcp_lease))
250247
{
251-
DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n");
248+
DEBUG_WIFI("[APConfig] server set_dhcps_lease failed!\n");
252249
ret = false;
253250
}
254251

255-
server.setRouter(true); // send ROUTER option with netif's gateway IP
256-
server.begin();
252+
// send ROUTER option with netif's gateway IP
253+
server.setRouter(true);
254+
255+
wifi_softap_dhcps_start();
257256

258257
// check config
259258
if(wifi_get_ip_info(SOFTAP_IF, &info)) {

0 commit comments

Comments
 (0)