Skip to content

Commit 88f5091

Browse files
blocking begin call on dhcp acquisition
1 parent 7e88a57 commit 88f5091

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

libraries/lwIpWrapper/src/CNetIf.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

333343
void 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

463473
err_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);
582592
exit:
583593
return res;
584594
}

libraries/lwIpWrapper/src/CNetIf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class CNetIf: public NetworkInterface {
180180
struct netif ni;
181181

182182
#ifdef LWIP_DHCP
183-
bool dhcp_acquired;
183+
volatile bool dhcp_acquired;
184184
#endif
185185

186186
/*

0 commit comments

Comments
 (0)