@@ -179,10 +179,8 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
179
179
* @param local_ip access point IP
180
180
* @param gateway gateway IP
181
181
* @param subnet subnet mask
182
- * @param dhcp_start first IP assigned by DHCP
183
- * @param dhcp_end last IP assigned by DHCP
184
182
*/
185
- bool ESP8266WiFiAPClass::softAPConfig (IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_start, IPAddress dhcp_end ) {
183
+ bool ESP8266WiFiAPClass::softAPConfig (IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
186
184
DEBUG_WIFI (" [APConfig] local_ip: %s gateway: %s subnet: %s\n " , local_ip.toString ().c_str (), gateway.toString ().c_str (), subnet.toString ().c_str ());
187
185
if (!WiFi.enableAP (true )) {
188
186
// enable AP failed
@@ -206,52 +204,35 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA
206
204
}
207
205
208
206
struct dhcps_lease dhcp_lease;
207
+ IPAddress ip = local_ip;
208
+ ip[3 ] += 99 ;
209
+ dhcp_lease.start_ip .addr = static_cast <uint32_t >(ip);
210
+ DEBUG_WIFI (" [APConfig] DHCP IP start: %s\n " , ip.toString ().c_str ());
209
211
210
- uint32_t net_addr = info.ip .addr & info.netmask .addr ;
211
- uint32_t bcast_addr = net_addr | !info.netmask .addr ;
212
-
213
- // Assign user-supplied range, checking its validity
214
- IPAddress ip = (static_cast <uint32_t >(dhcp_start) & !info.netmask .addr ) | net_addr;
212
+ ip[3 ] += 100 ;
213
+ dhcp_lease.end_ip .addr = static_cast <uint32_t >(ip);
214
+ DEBUG_WIFI (" [APConfig] DHCP IP end: %s\n " , ip.toString ().c_str ());
215
215
216
- dhcp_lease.start_ip .addr = ip;
217
- if (ip != net_addr && ip != bcast_addr && ip != info.ip .addr && ip != info.gw .addr ) {
218
- DEBUG_WIFI (" [APConfig] DHCP IP start: %s\n " , ip.toString ().c_str ());
219
- } else {
220
- dhcp_lease.start_ip .addr =0 ;
216
+ if (!wifi_softap_set_dhcps_lease (&dhcp_lease)) {
217
+ DEBUG_WIFI (" [APConfig] wifi_set_ip_info failed!\n " );
218
+ ret = false ;
221
219
}
222
220
223
- ip = (static_cast <uint32_t >(dhcp_end) & !info.netmask .addr ) | net_addr;
224
- dhcp_lease.end_ip .addr = static_cast <uint32_t >(ip);
225
- if (ip != net_addr && ip != bcast_addr && ip != info.ip .addr && ip != info.gw .addr ) {
226
- DEBUG_WIFI (" [APConfig] DHCP IP end: %s\n " , ip.toString ().c_str ());
227
- } else {
228
- dhcp_lease.end_ip .addr =0 ;
221
+ // set lease time to 720min --> 12h
222
+ if (!wifi_softap_set_dhcps_lease_time (720 )) {
223
+ DEBUG_WIFI (" [APConfig] wifi_softap_set_dhcps_lease_time failed!\n " );
224
+ ret = false ;
229
225
}
230
226
231
- if (dhcp_lease.start_ip .addr && dhcp_lease.end_ip .addr ) {
232
- if (!wifi_softap_set_dhcps_lease (&dhcp_lease)) {
233
- DEBUG_WIFI (" [APConfig] wifi_set_ip_info failed!\n " );
234
- ret = false ;
235
- }
236
-
237
- // set lease time to 720min --> 12h
238
- if (!wifi_softap_set_dhcps_lease_time (720 )) {
239
- DEBUG_WIFI (" [APConfig] wifi_softap_set_dhcps_lease_time failed!\n " );
240
- ret = false ;
241
- }
242
-
243
- uint8 mode = 1 ;
244
- if (!wifi_softap_set_dhcps_offer_option (OFFER_ROUTER, &mode)) {
245
- DEBUG_WIFI (" [APConfig] wifi_softap_set_dhcps_offer_option failed!\n " );
246
- ret = false ;
247
- }
227
+ uint8 mode = 1 ;
228
+ if (!wifi_softap_set_dhcps_offer_option (OFFER_ROUTER, &mode)) {
229
+ DEBUG_WIFI (" [APConfig] wifi_softap_set_dhcps_offer_option failed!\n " );
230
+ ret = false ;
231
+ }
248
232
249
- if (!wifi_softap_dhcps_start ()) {
250
- DEBUG_WIFI (" [APConfig] wifi_softap_dhcps_start failed!\n " );
251
- ret = false ;
252
- }
253
- } else {
254
- DEBUG_WIFI (" [APConfig] DHCP daemon not started (range error or user request)\n " );
233
+ if (!wifi_softap_dhcps_start ()) {
234
+ DEBUG_WIFI (" [APConfig] wifi_softap_dhcps_start failed!\n " );
235
+ ret = false ;
255
236
}
256
237
257
238
// check config
@@ -273,25 +254,6 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA
273
254
}
274
255
275
256
276
- /* *
277
- * Configure access point
278
- * @param local_ip access point IP
279
- * @param gateway gateway IP
280
- * @param subnet subnet mask
281
- */
282
- bool ESP8266WiFiAPClass::softAPConfig (IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
283
- IPAddress dhcp_start;
284
- IPAddress dhcp_end;
285
-
286
- // calculate dhcp_start and DHCP_end as done in the old code
287
- dhcp_start = local_ip;
288
- dhcp_start[3 ] += 99 ;
289
- dhcp_end = dhcp_start;
290
- dhcp_end[3 ] += 100 ;
291
-
292
- softAPConfig (local_ip, gateway, subnet, dhcp_start, dhcp_end);
293
- }
294
-
295
257
296
258
/* *
297
259
* Disconnect from the network (close AP)
0 commit comments