diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index f98e8ac50..da8870584 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -339,6 +339,29 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress a return true; } +/** + * Change DNS for static IP configuration + * @param dns1 Static DNS server 1 + * @param dns2 Static DNS server 2 (optional) + */ +bool ESP8266WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2) { + + if((WiFi.getMode() & WIFI_STA) == 0) + return false; + + if(dns1.isSet()) { + // Set DNS1-Server + dns_setserver(0, dns1); + } + + if(dns2.isSet()) { + // Set DNS2-Server + dns_setserver(1, dns2); + } + + return true; +} + /** * will force a disconnect an then start reconnecting to AP * @return ok diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h index 11f188a6d..c5b4d3862 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h @@ -45,7 +45,8 @@ class ESP8266WiFiSTAClass: public LwipIntf { //The argument order for ESP is not the same as for Arduino. However, there is compatibility code under the hood //to detect Arduino arg order, and handle it correctly. Be aware that the Arduino default value handling doesn't //work here (see Arduino docs for gway/subnet defaults). In other words: at least 3 args must always be given. - bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000); + bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = INADDR_ANY, IPAddress dns2 = INADDR_ANY); + bool setDNS(IPAddress dns1, IPAddress dns2 = INADDR_ANY); bool reconnect();