@@ -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)) {
@@ -277,7 +276,7 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA
277276/* *
278277 * Disconnect from the network (close AP)
279278 * @param wifioff disable mode?
280- * @return one value of wl_status_t enum
279+ * @return operation success
281280 */
282281bool ESP8266WiFiAPClass::softAPdisconnect (bool wifioff) {
283282 bool ret;
0 commit comments