From d1fe22a581b9af7bfee97ef162b30ce94a0fc8c8 Mon Sep 17 00:00:00 2001 From: Juraj Andrassy Date: Wed, 8 Nov 2023 15:33:25 +0100 Subject: [PATCH] WiFiSTA - method setDNS as in WiFi libraries by Arduino https://www.arduino.cc/reference/en/libraries/wifi/wifi.setdns/ --- libraries/WiFi/src/WiFiSTA.cpp | 13 +++++++++++++ libraries/WiFi/src/WiFiSTA.h | 1 + 2 files changed, 14 insertions(+) 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);