Fix DNS servers not sticking when static IP address is used
This commit is contained in:
committed by
Sandeep Mistry
parent
2aed17fc1e
commit
bd477c1d6b
@@ -43,6 +43,7 @@ WiFiClass::WiFiClass() :
|
||||
_eventGroup = xEventGroupCreate();
|
||||
memset(&_apRecord, 0x00, sizeof(_apRecord));
|
||||
memset(&_ipInfo, 0x00, sizeof(_ipInfo));
|
||||
memset(&_dnsServers, 0x00, sizeof(_dnsServers));
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::status()
|
||||
@@ -303,6 +304,9 @@ void WiFiClass::setDNS(/*IPAddress*/uint32_t dns_server1, /*IPAddress*/uint32_t
|
||||
ip_addr_t d;
|
||||
d.type = IPADDR_TYPE_V4;
|
||||
|
||||
_dnsServers[0] = dns_server1;
|
||||
_dnsServers[1] = dns_server2;
|
||||
|
||||
if (dns_server1) {
|
||||
d.u_addr.ip4.addr = static_cast<uint32_t>(dns_server1);
|
||||
dns_setserver(0, &d);
|
||||
@@ -622,6 +626,9 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
|
||||
esp_wifi_sta_get_ap_info(&_apRecord);
|
||||
|
||||
if (_ipInfo.ip.addr) {
|
||||
// re-apply the custom DNS settings
|
||||
setDNS(_dnsServers[0], _dnsServers[1]);
|
||||
|
||||
// static IP
|
||||
_status = WL_CONNECTED;
|
||||
}
|
||||
@@ -647,6 +654,7 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
|
||||
|
||||
case SYSTEM_EVENT_STA_LOST_IP:
|
||||
memset(&_ipInfo, 0x00, sizeof(_ipInfo));
|
||||
memset(&_dnsServers, 0x00, sizeof(_dnsServers));
|
||||
_status = WL_CONNECTION_LOST;
|
||||
break;
|
||||
|
||||
@@ -672,6 +680,9 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
|
||||
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP);
|
||||
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &_ipInfo);
|
||||
tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP);
|
||||
|
||||
// re-apply the custom DNS settings
|
||||
setDNS(_dnsServers[0], _dnsServers[1]);
|
||||
} else {
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &_ipInfo);
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ private:
|
||||
wifi_ap_record_t _scanResults[MAX_SCAN_RESULTS];
|
||||
wifi_ap_record_t _apRecord;
|
||||
tcpip_adapter_ip_info_t _ipInfo;
|
||||
uint32_t _dnsServers[2];
|
||||
|
||||
netif_input_fn _staNetifInput;
|
||||
netif_input_fn _apNetifInput;
|
||||
|
||||
Reference in New Issue
Block a user