@@ -316,18 +316,28 @@ int CNetIf::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress &gw)
316316
317317 netif_set_up (&this ->ni );
318318
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+
319323#ifdef LWIP_DHCP
320324 // dhcp is started when begin gets ip == nullptr
321325 if (ip != INADDR_NONE) {
322326 this ->dhcpNotUsed ();
323327 } else {
324328 this ->dhcpStart ();
329+
330+
331+ CLwipIf::getInstance ().sync_timer ();
332+ while (!this ->isDhcpAcquired ()) {
333+ CLwipIf::getInstance ().task ();
334+ }
335+ CLwipIf::getInstance ().enable_timer ();
325336 }
337+
326338#endif
327339
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 ;
331341}
332342
333343void CNetIf::task () {
@@ -452,12 +462,12 @@ int CEth::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress &gw, c
452462 this , std::placeholders:: _1, std::placeholders::_2));
453463
454464 // 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 );
457467
458468 CLwipIf::getInstance ().addDnsServer (dns);
459469
460- return 0 ;
470+ return res ;
461471}
462472
463473err_t CEth::init (struct netif * ni) {
@@ -578,7 +588,7 @@ int CWifiStation::begin(const IPAddress &ip, const IPAddress &nm, const IPAddres
578588 res = CEspControl::getInstance ().setWifiMode (WIFI_MODE_STA);
579589 CLwipIf::getInstance ().enable_timer ();
580590
581- CNetIf::begin (ip, nm, gw);
591+ return CNetIf::begin (ip, nm, gw);
582592exit:
583593 return res;
584594}
0 commit comments