diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index b2ae6a28a94..f61e300bb51 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -430,6 +430,19 @@ bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subne return err == ESP_OK; } +/** + * Change DNS server for static IP configuration + * @param dns1 Static DNS server 1 + * @param dns2 Static DNS server 2 (optional) + */ +bool WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2) +{ + if(WiFiGenericClass::getMode() == WIFI_MODE_NULL) + return false; + esp_err_t err = set_esp_interface_dns(ESP_IF_WIFI_STA, dns1, dns2); + return err == ESP_OK; +} + /** * is STA interface connected? * @return true if STA is connected to an AP diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index 0b8f9daf053..fb80578ca3b 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -56,6 +56,7 @@ class WiFiSTAClass wl_status_t begin(); bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000); + bool setDNS(IPAddress dns1, IPAddress dns2 = (uint32_t)0x00000000); // sets DNS IP for all network interfaces bool reconnect(); bool disconnect(bool wifioff = false, bool eraseap = false);