Skip to content

Commit eed76e2

Browse files
committed
fix switching to static address with lwip2
For some reason, ip address is not propagated in a visible way for lwip2 when switching to static address (wifi.config()) *after* wifi.begin(). This patch calls lwip-v1.4's netif_set_addr() with the new ip address to set all things up, just like it is done and right when wifi.begin() is called after wifi.config(). Also tested when IPv6 is enabled. fixes esp8266#5839 fixes esp8266#6024
1 parent feb3988 commit eed76e2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ wl_status_t ESP8266WiFiSTAClass::begin() {
247247
* @param dns1 Static DNS server 1
248248
* @param dns2 Static DNS server 2
249249
*/
250+
251+
#if LWIP_VERSION_MAJOR != 1
252+
#undef netif_set_addr // need to call lwip-v1.4 netif_set_addr()
253+
extern "C" struct netif* eagle_lwip_getif (int netif_index);
254+
extern "C" void netif_set_addr (struct netif* netif, ip4_addr_t* ip, ip4_addr_t* netmask, ip4_addr_t* gw);
255+
#endif
256+
250257
bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress arg2, IPAddress arg3, IPAddress dns2) {
251258

252259
if(!WiFi.enableSTA(true)) {
@@ -310,6 +317,11 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress a
310317
dns_setserver(1, dns2);
311318
}
312319

320+
#if LWIP_VERSION_MAJOR != 1
321+
// trigger address change by calling lwip-v1.4 api
322+
netif_set_addr(eagle_lwip_getif(STATION_IF), &info.ip, &info.netmask, &info.gw);
323+
#endif
324+
313325
return true;
314326
}
315327

0 commit comments

Comments
 (0)