Skip to content

Commit fbfcb80

Browse files
authored
WiFiSTA - method setDNS as in WiFi libraries by Arduino (#8854)
https://www.arduino.cc/reference/en/libraries/wifi/wifi.setdns/
1 parent 0b6d20e commit fbfcb80

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: libraries/WiFi/src/WiFiSTA.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,19 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne
431431
return err == ESP_OK;
432432
}
433433

434+
/**
435+
* Change DNS server for static IP configuration
436+
* @param dns1 Static DNS server 1
437+
* @param dns2 Static DNS server 2 (optional)
438+
*/
439+
bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2)
440+
{
441+
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL)
442+
return false;
443+
esp_err_t err = set_esp_interface_dns(ESP_IF_WIFI_STA, dns1, dns2);
444+
return err == ESP_OK;
445+
}
446+
434447
/**
435448
* is STA interface connected?
436449
* @return true if STA is connected to an AP

Diff for: libraries/WiFi/src/WiFiSTA.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class WiFiSTAClass
5656
wl_status_t begin();
5757

5858
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
59+
bool setDNS(IPAddress dns1, IPAddress dns2 = (uint32_t)0x00000000); // sets DNS IP for all network interfaces
5960

6061
bool reconnect();
6162
bool disconnect(bool wifioff = false, bool eraseap = false);

0 commit comments

Comments
 (0)