diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index e62ac68b526..06425c00120 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -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 diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index 385be487120..d04a16d13d8 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -116,8 +116,12 @@ class WiFiSTAClass } 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);