Skip to content

Commit 702daa0

Browse files
authored
Merge pull request #918 from JAndrassy/net_staticip_dns_fix
Ethernet and WiFi - fix DNS for static IP
2 parents 680e430 + 1718628 commit 702daa0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

libraries/Ethernet/src/Ethernet.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPA
5555

5656
eth_if->set_dhcp(false);
5757
eth_if->set_network(_ip, _netmask, _gateway);
58+
59+
auto ret = _begin(mac, timeout, responseTimeout);
60+
5861
char if_name[5];
5962
eth_if->get_interface_name(if_name);
6063
eth_if->add_dns_server(_dnsServer1, if_name);
6164

62-
auto ret = _begin(mac, timeout, responseTimeout);
6365
return ret;
6466
}
6567

libraries/WiFi/src/WiFi.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,18 @@ int arduino::WiFiClass::begin(const char* ssid, const char* passphrase, wl_enc_t
6666
wifi_if->set_dhcp(!_useStaticIP);
6767
if (_useStaticIP) {
6868
wifi_if->set_network(_ip, _netmask, _gateway);
69-
char if_name[5];
70-
wifi_if->get_interface_name(if_name);
71-
wifi_if->add_dns_server(_dnsServer2, if_name);
72-
wifi_if->add_dns_server(_dnsServer1, if_name); // pushes dnsServer2 at index 1
7369
}
7470

7571
nsapi_error_t result = wifi_if->connect(ssid, passphrase, _security);
7672

7773
if(result == NSAPI_ERROR_IS_CONNECTED) {
7874
wifi_if->disconnect();
75+
} else
76+
if (_useStaticIP) {
77+
char if_name[5];
78+
wifi_if->get_interface_name(if_name);
79+
wifi_if->add_dns_server(_dnsServer2, if_name);
80+
wifi_if->add_dns_server(_dnsServer1, if_name); // pushes dnsServer2 at index 1
7981
}
8082
_currentNetworkStatus = (result == NSAPI_ERROR_OK && setSSID(ssid)) ? WL_CONNECTED : WL_CONNECT_FAILED;
8183

0 commit comments

Comments
 (0)