Skip to content

Commit d44a5bb

Browse files
committed
WiFiSTA - method setDNS as in WiFi libraries by Arduino
https://www.arduino.cc/reference/en/libraries/wifi/wifi.setdns/
1 parent 31c1592 commit d44a5bb

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,29 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress a
339339
return true;
340340
}
341341

342+
/**
343+
* Change DNS for static IP configuration
344+
* @param dns1 Static DNS server 1
345+
* @param dns2 Static DNS server 2 (optional)
346+
*/
347+
bool ESP8266WiFiSTAClass::setDNS(IPAddress dns1, IPAddress dns2) {
348+
349+
if((WiFi.getMode() & WIFI_STA) == 0)
350+
return false;
351+
352+
if(dns1.isSet()) {
353+
// Set DNS1-Server
354+
dns_setserver(0, dns1);
355+
}
356+
357+
if(dns2.isSet()) {
358+
// Set DNS2-Server
359+
dns_setserver(1, dns2);
360+
}
361+
362+
return true;
363+
}
364+
342365
/**
343366
* will force a disconnect an then start reconnecting to AP
344367
* @return ok

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ESP8266WiFiSTAClass: public LwipIntf {
4646
//to detect Arduino arg order, and handle it correctly. Be aware that the Arduino default value handling doesn't
4747
//work here (see Arduino docs for gway/subnet defaults). In other words: at least 3 args must always be given.
4848
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
49+
bool setDNS(IPAddress dns1, IPAddress dns2 = (uint32_t)0x00000000);
4950

5051
bool reconnect();
5152

0 commit comments

Comments
 (0)