Skip to content

Commit

Permalink
WiFiSTA - method setDNS as in WiFi libraries by Arduino (espressif#8854)
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Nov 10, 2023
1 parent 0b6d20e commit fbfcb80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libraries/WiFi/src/WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,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
Expand Down
1 change: 1 addition & 0 deletions libraries/WiFi/src/WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fbfcb80

Please sign in to comment.