1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-21 21:22:31 +03:00

WiFi - static IP auto gw,mask,dns as in Arduino libraries (#9031)

This commit is contained in:
Juraj Andrássy
2023-11-24 10:10:27 +01:00
committed by GitHub
parent 32c858df6d
commit 9a4e17876e
2 changed files with 21 additions and 0 deletions

View File

@ -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.isSet()) {
dns = gw;
}
return config(local_ip, dns, gw);
}
/**
* Change DNS for static IP configuration
* @param dns1 Static DNS server 1

View File

@ -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();