Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c1885f

Browse filesBrowse files
JAndrassyme-no-dev
andauthored
WiFi.config handle Arduino parameters ordering and auto dns,gw,mask (espressif#9425)
Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
1 parent 0523b94 commit 3c1885f
Copy full SHA for 3c1885f

File tree

2 files changed

+30
-0
lines changed
Filter options

2 files changed

+30
-0
lines changed

‎libraries/WiFi/src/WiFiSTA.cpp

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiSTA.cpp
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,35 @@ bool WiFiSTAClass::eraseAP(void) {
169169
*/
170170
bool WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)
171171
{
172+
// handle Arduino ordering of parameters: ip, dns, gw, subnet
173+
if (local_ip.type() == IPv4 && local_ip != INADDR_NONE && subnet[0] != 255) {
174+
IPAddress tmp = dns1;
175+
dns1 = gateway;
176+
gateway = subnet;
177+
subnet = (tmp != INADDR_NONE) ? tmp : IPAddress(255, 255, 255, 0);
178+
}
179+
172180
return STA.config(local_ip, gateway, subnet, dns1, dns2);
173181
}
174182

183+
bool WiFiSTAClass::config(IPAddress local_ip, IPAddress dns) {
184+
185+
if (local_ip == INADDR_NONE) {
186+
return config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
187+
}
188+
189+
if (local_ip.type() != IPv4) {
190+
return false;
191+
}
192+
193+
IPAddress gw(local_ip);
194+
gw[3] = 1;
195+
if (dns == INADDR_NONE) {
196+
dns = gw;
197+
}
198+
return config(local_ip, gw, IPAddress(255, 255, 255, 0), dns);
199+
}
200+
175201
/**
176202
* Change DNS server for static IP configuration
177203
* @param dns1 Static DNS server 1

‎libraries/WiFi/src/WiFiSTA.h

Copy file name to clipboardExpand all lines: libraries/WiFi/src/WiFiSTA.h
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ class WiFiSTAClass
116116
}
117117
wl_status_t begin();
118118

119+
// also accepts Arduino ordering of parameters: ip, dns, gw, mask
119120
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
120121

122+
// two and one parameter version. 2nd parameter is DNS like in Arduino
123+
bool config(IPAddress local_ip, IPAddress dns = (uint32_t)0x00000000);
124+
121125
bool setDNS(IPAddress dns1, IPAddress dns2 = (uint32_t)0x00000000); // sets DNS IP for all network interfaces
122126

123127
bool bandwidth(wifi_bandwidth_t bandwidth);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.