Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethernet and WiFi - fix DNS for static IP #918

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPA

eth_if->set_dhcp(false);
eth_if->set_network(_ip, _netmask, _gateway);

auto ret = _begin(mac, timeout, responseTimeout);

char if_name[5];
eth_if->get_interface_name(if_name);
eth_if->add_dns_server(_dnsServer1, if_name);

auto ret = _begin(mac, timeout, responseTimeout);
return ret;
}

Expand Down
10 changes: 6 additions & 4 deletions libraries/WiFi/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ int arduino::WiFiClass::begin(const char* ssid, const char* passphrase, wl_enc_t
wifi_if->set_dhcp(!_useStaticIP);
if (_useStaticIP) {
wifi_if->set_network(_ip, _netmask, _gateway);
char if_name[5];
wifi_if->get_interface_name(if_name);
wifi_if->add_dns_server(_dnsServer2, if_name);
wifi_if->add_dns_server(_dnsServer1, if_name); // pushes dnsServer2 at index 1
}

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

if(result == NSAPI_ERROR_IS_CONNECTED) {
wifi_if->disconnect();
} else
if (_useStaticIP) {
char if_name[5];
wifi_if->get_interface_name(if_name);
wifi_if->add_dns_server(_dnsServer2, if_name);
wifi_if->add_dns_server(_dnsServer1, if_name); // pushes dnsServer2 at index 1
}
_currentNetworkStatus = (result == NSAPI_ERROR_OK && setSSID(ssid)) ? WL_CONNECTED : WL_CONNECT_FAILED;

Expand Down
Loading