File tree Expand file tree Collapse file tree 2 files changed +15
-20
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +15
-20
lines changed
Original file line number Diff line number Diff line change @@ -205,23 +205,7 @@ bool WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress
205
205
}
206
206
207
207
err = set_esp_interface_ip (ESP_IF_WIFI_AP, local_ip, gateway, subnet);
208
-
209
- // testing effectiveness of the operation beyond internal DHCP Client process
210
- esp_netif_ip_info_t ip;
211
- if (esp_netif_get_ip_info (get_esp_interface_netif (ESP_IF_WIFI_AP), &ip) != ESP_OK){
212
- log_e (" Netif Get IP Failed!" );
213
- return false ;
214
- }
215
- bool ip_ok = IPAddress (ip.ip .addr ) == local_ip;
216
- bool gw_ok = IPAddress (ip.gw .addr ) == gateway;
217
- bool mk_ok = IPAddress (ip.netmask .addr ) == subnet;
218
-
219
- if (ip_ok && gw_ok && mk_ok) {
220
- return true ;
221
- } else {
222
- log_e (" Failed setting: %s %s %s" , ip_ok ? " " : " Static IP" , gw_ok ? " " : " - Gateway" , mk_ok ? " " : " - Netmask" );
223
- return false ;
224
- }
208
+ return err == ESP_OK;
225
209
}
226
210
227
211
Original file line number Diff line number Diff line change @@ -138,9 +138,20 @@ esp_err_t set_esp_interface_ip(esp_interface_t interface, IPAddress local_ip=IPA
138
138
139
139
dhcps_lease_t lease;
140
140
lease.enable = true ;
141
- lease.start_ip .addr = static_cast <uint32_t >(local_ip) + (1 << 24 );
142
- lease.end_ip .addr = static_cast <uint32_t >(local_ip) + (11 << 24 );
143
-
141
+ uint32_t dhcp_ipaddr = static_cast <uint32_t >(local_ip);
142
+ // prevents DHCP lease range to overflow subnet/24 range
143
+ // there will be 11 addresses for DHCP to lease
144
+ uint8_t leaseStart = (uint8_t )(~subnet[3 ] - 12 );
145
+ if ((local_ip[3 ]) < leaseStart) {
146
+ lease.start_ip .addr = dhcp_ipaddr + (1 << 24 );
147
+ lease.end_ip .addr = dhcp_ipaddr + (11 << 24 );
148
+ } else {
149
+ // make range stay in the begining of the netmask range
150
+ dhcp_ipaddr = (dhcp_ipaddr & 0x00FFFFFF );
151
+ lease.start_ip .addr = dhcp_ipaddr + (1 << 24 );
152
+ lease.end_ip .addr = dhcp_ipaddr + (11 << 24 );
153
+ }
154
+ log_v (" DHCP Server Range: %s to %s" , IPAddress (lease.start_ip .addr ).toString (), IPAddress (lease.end_ip .addr ).toString ());
144
155
err = tcpip_adapter_dhcps_option (
145
156
(tcpip_adapter_dhcp_option_mode_t )TCPIP_ADAPTER_OP_SET,
146
157
(tcpip_adapter_dhcp_option_id_t )REQUESTED_IP_ADDRESS,
You can’t perform that action at this time.
0 commit comments