Skip to content

Commit

Permalink
WiFiSTA - method setDNS as in WiFi libraries by Arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Nov 8, 2023
1 parent 31c1592 commit d44a5bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ESP8266WiFiSTAClass: public LwipIntf {
//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 setDNS(IPAddress dns1, IPAddress dns2 = (uint32_t)0x00000000);

bool reconnect();

Expand Down

0 comments on commit d44a5bb

Please sign in to comment.