Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d1fe22a

Browse files
committedNov 10, 2023
WiFiSTA - method setDNS as in WiFi libraries by Arduino
https://www.arduino.cc/reference/en/libraries/wifi/wifi.setdns/
1 parent 6d9ebea commit d1fe22a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
 

‎libraries/WiFi/src/WiFiSTA.cpp

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

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

‎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)
Please sign in to comment.