Skip to content

Commit d4eff48

Browse files
authored
Update WiFiGeneric.cpp
1 parent a5dedc4 commit d4eff48

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

libraries/WiFi/src/WiFiGeneric.cpp

+22-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,20 @@ esp_err_t set_esp_interface_ip(esp_interface_t interface, IPAddress local_ip=IPA
138138

139139
dhcps_lease_t lease;
140140
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());
144155
err = tcpip_adapter_dhcps_option(
145156
(tcpip_adapter_dhcp_option_mode_t)TCPIP_ADAPTER_OP_SET,
146157
(tcpip_adapter_dhcp_option_id_t)REQUESTED_IP_ADDRESS,
@@ -1061,6 +1072,14 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
10611072
if(!espWiFiStart()){
10621073
return false;
10631074
}
1075+
1076+
#ifdef BOARD_HAS_DUAL_ANTENNA
1077+
if(!setDualAntennaConfig(ANT1, ANT2, WIFI_RX_ANT_AUTO, WIFI_TX_ANT_AUTO)){
1078+
log_e("Dual Antenna Config failed!");
1079+
return false;
1080+
}
1081+
#endif
1082+
10641083
return true;
10651084
}
10661085

0 commit comments

Comments
 (0)