@@ -247,6 +247,27 @@ wl_status_t ESP8266WiFiSTAClass::begin() {
247
247
* @param dns1 Static DNS server 1
248
248
* @param dns2 Static DNS server 2
249
249
*/
250
+
251
+ #if LWIP_VERSION_MAJOR != 1
252
+ /*
253
+ About the following call in the end of ESP8266WiFiSTAClass::config():
254
+ netif_set_addr(eagle_lwip_getif(STATION_IF), &info.ip, &info.netmask, &info.gw);
255
+
256
+ With lwip2, it is needed to trigger IP address change.
257
+ Recall: when lwip2 is enabled, lwip1 api is still used by espressif firmware
258
+ https://github.com/d-a-v/esp82xx-nonos-linklayer/tree/25d5e8186f710a230221021cba97727dbfdfd953#how-it-works
259
+
260
+ We need first to disable the lwIP API redirection for netif_set_addr() so lwip1's call will be linked:
261
+ https://github.com/d-a-v/esp82xx-nonos-linklayer/blob/25d5e8186f710a230221021cba97727dbfdfd953/glue-lwip/arch/cc.h#L122
262
+
263
+ We also need to declare its prototype using ip4_addr_t instead of ip_addr_t because lwIP-1.x never has IPv6.
264
+ No need to worry about this #undef, this call is only needed in lwip2, and never used in arduino core code.
265
+ */
266
+ #undef netif_set_addr // need to call lwIP-v1.4 netif_set_addr()
267
+ extern " C" struct netif * eagle_lwip_getif (int netif_index);
268
+ extern " C" void netif_set_addr (struct netif * netif, ip4_addr_t * ip, ip4_addr_t * netmask, ip4_addr_t * gw);
269
+ #endif
270
+
250
271
bool ESP8266WiFiSTAClass::config (IPAddress local_ip, IPAddress arg1, IPAddress arg2, IPAddress arg3, IPAddress dns2) {
251
272
252
273
if (!WiFi.enableSTA (true )) {
@@ -310,6 +331,12 @@ bool ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress arg1, IPAddress a
310
331
dns_setserver (1 , dns2);
311
332
}
312
333
334
+ #if LWIP_VERSION_MAJOR != 1
335
+ // trigger address change by calling lwIP-v1.4 api
336
+ // (see explanation above)
337
+ netif_set_addr (eagle_lwip_getif (STATION_IF), &info.ip , &info.netmask , &info.gw );
338
+ #endif
339
+
313
340
return true ;
314
341
}
315
342
0 commit comments