Skip to content

Commit 59db907

Browse files
authored
lwip2: (re)fix setting static ip address (#6194)
1 parent 9f03bbb commit 59db907

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress a
309309
return false;
310310
}
311311

312+
#if LWIP_VERSION_MAJOR != 1 && !CORE_MOCK
313+
// get current->previous IP address
314+
// (check below)
315+
struct ip_info previp;
316+
wifi_get_ip_info(STATION_IF, &previp);
317+
#endif
318+
312319
struct ip_info info;
313320
info.ip.addr = local_ip.v4();
314321
info.gw.addr = gateway.v4();
@@ -334,7 +341,9 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress a
334341
#if LWIP_VERSION_MAJOR != 1 && !CORE_MOCK
335342
// trigger address change by calling lwIP-v1.4 api
336343
// (see explanation above)
337-
netif_set_addr(eagle_lwip_getif(STATION_IF), &info.ip, &info.netmask, &info.gw);
344+
// only when ip is already set by other mean (generally dhcp)
345+
if (previp.ip.addr != 0 && previp.ip.addr != info.ip.addr)
346+
netif_set_addr(eagle_lwip_getif(STATION_IF), &info.ip, &info.netmask, &info.gw);
338347
#endif
339348

340349
return true;

0 commit comments

Comments
 (0)