@@ -316,18 +316,28 @@ int CNetIf::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress &gw)
316
316
317
317
netif_set_up (&this ->ni );
318
318
319
+ // add the interface to the network stack
320
+ CLwipIf::getInstance ().add_iface (this ); // TODO remove interface when it is needed (??)
321
+ netif_set_link_up (&this ->ni );
322
+
319
323
#ifdef LWIP_DHCP
320
324
// dhcp is started when begin gets ip == nullptr
321
325
if (ip != INADDR_NONE) {
322
326
this ->dhcpNotUsed ();
323
327
} else {
324
328
this ->dhcpStart ();
329
+
330
+
331
+ CLwipIf::getInstance ().sync_timer ();
332
+ while (!this ->isDhcpAcquired ()) {
333
+ CLwipIf::getInstance ().task ();
334
+ }
335
+ CLwipIf::getInstance ().enable_timer ();
325
336
}
337
+
326
338
#endif
327
339
328
- // add the interface to the network stack
329
- CLwipIf::getInstance ().add_iface (this ); // TODO remove interface when it is needed (??)
330
- return 0 ;
340
+ return this ->isDhcpAcquired ()? 1 : 0 ;
331
341
}
332
342
333
343
void CNetIf::task () {
@@ -452,12 +462,12 @@ int CEth::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress &gw, c
452
462
this , std::placeholders:: _1, std::placeholders::_2));
453
463
454
464
// Call the begin function on the Parent class to init the interface
455
- CNetIf::begin (ip, nm, gw );
456
- netif_set_link_up (& this -> ni );
465
+ // netif_set_link_up(&this->ni );
466
+ auto res = CNetIf::begin (ip, nm, gw );
457
467
458
468
CLwipIf::getInstance ().addDnsServer (dns);
459
469
460
- return 0 ;
470
+ return res ;
461
471
}
462
472
463
473
err_t CEth::init (struct netif * ni) {
@@ -578,7 +588,7 @@ int CWifiStation::begin(const IPAddress &ip, const IPAddress &nm, const IPAddres
578
588
res = CEspControl::getInstance ().setWifiMode (WIFI_MODE_STA);
579
589
CLwipIf::getInstance ().enable_timer ();
580
590
581
- CNetIf::begin (ip, nm, gw);
591
+ return CNetIf::begin (ip, nm, gw);
582
592
exit :
583
593
return res;
584
594
}
0 commit comments