Skip to content

Commit

Permalink
WiFi - static IP auto gw,mask,dns as in Arduino libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Nov 15, 2023
1 parent 7fc2caa commit 3f5dff6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,22 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress a
return true;
}

bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) {

if (!local_ip.isSet())
return config(INADDR_ANY, INADDR_ANY, INADDR_ANY);

if (!local_ip.isV4())
return false;

IPAddress gw(local_ip);
gw[3] = 1;
if (dns == IPADDR_NONE) {
dns = gw;
}
return config(local_ip, dns, gw);
}

/**
* Change DNS for static IP configuration
* @param dns1 Static DNS server 1
Expand Down
5 changes: 5 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ 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 = INADDR_ANY, IPAddress dns2 = INADDR_ANY);

// two and one parameter version. 2nd parameter is DNS like in Arduino
// IPv4 only
bool config(IPAddress local_ip, IPAddress dns = INADDR_ANY);

bool setDNS(IPAddress dns1, IPAddress dns2 = INADDR_ANY);

bool reconnect();
Expand Down

0 comments on commit 3f5dff6

Please sign in to comment.