Skip to content

Commit f9d9063

Browse files
JAndrassyhasenradball
authored andcommitted
WiFi - static IP auto gw,mask,dns as in Arduino libraries (esp8266#9031)
1 parent ab22b4a commit f9d9063

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

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

342+
bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) {
343+
344+
if (!local_ip.isSet())
345+
return config(INADDR_ANY, INADDR_ANY, INADDR_ANY);
346+
347+
if (!local_ip.isV4())
348+
return false;
349+
350+
IPAddress gw(local_ip);
351+
gw[3] = 1;
352+
if (!dns.isSet()) {
353+
dns = gw;
354+
}
355+
return config(local_ip, dns, gw);
356+
}
357+
342358
/**
343359
* Change DNS for static IP configuration
344360
* @param dns1 Static DNS server 1

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ 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 = INADDR_ANY, IPAddress dns2 = INADDR_ANY);
49+
50+
// two and one parameter version. 2nd parameter is DNS like in Arduino
51+
// IPv4 only
52+
bool config(IPAddress local_ip, IPAddress dns = INADDR_ANY);
53+
4954
bool setDNS(IPAddress dns1, IPAddress dns2 = INADDR_ANY);
5055

5156
bool reconnect();

0 commit comments

Comments
 (0)