Unverified Commit 3c1885f8 authored by Juraj Andrássy's avatar Juraj Andrássy Committed by GitHub

WiFi.config handle Arduino parameters ordering and auto dns,gw,mask (#9425)

Co-authored-by: default avatarMe No Dev <me-no-dev@users.noreply.github.com>
parent 0523b94e
......@@ -169,9 +169,35 @@ bool WiFiSTAClass::eraseAP(void) {
*/
bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
{
// handle Arduino ordering of parameters: ip, dns, gw, subnet
if (local_ip.type() == IPv4 && local_ip != INADDR_NONE && subnet[0] != 255) {
IPAddress tmp = dns1;
dns1 = gateway;
gateway = subnet;
subnet = (tmp != INADDR_NONE) ? tmp : IPAddress(255, 255, 255, 0);
}
return STA.config(local_ip, gateway, subnet, dns1, dns2);
}
bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) {
if (local_ip == INADDR_NONE) {
return config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
}
if (local_ip.type() != IPv4) {
return false;
}
IPAddress gw(local_ip);
gw[3] = 1;
if (dns == INADDR_NONE) {
dns = gw;
}
return config(local_ip, gw, IPAddress(255, 255, 255, 0), dns);
}
/**
* Change DNS server for static IP configuration
* @param dns1 Static DNS server 1
......
......@@ -116,8 +116,12 @@ public:
}
wl_status_t begin();
// also accepts Arduino ordering of parameters: ip, dns, gw, mask
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
// two and one parameter version. 2nd parameter is DNS like in Arduino
bool config(IPAddress local_ip, IPAddress dns = (uint32_t)0x00000000);
bool setDNS(IPAddress dns1, IPAddress dns2 = (uint32_t)0x00000000); // sets DNS IP for all network interfaces
bool bandwidth(wifi_bandwidth_t bandwidth);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment