Skip to content

Commit b9dc628

Browse files
committed
LwipIntfDev - method end() to enable repeated begin
1 parent 31c1592 commit b9dc628

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

cores/esp8266/LwipIntfDev.h

+28-6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class LwipIntfDev: public LwipIntf, public RawDev
6868

6969
// default mac-address is inferred from esp8266's STA interface
7070
boolean begin(const uint8_t* macAddress = nullptr, const uint16_t mtu = DEFAULT_MTU);
71+
void end();
7172

7273
const netif* getNetIf() const
7374
{
@@ -272,22 +273,43 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
272273
}
273274
}
274275

275-
if (_intrPin < 0
276-
&& !schedule_recurrent_function_us(
276+
static bool _scheduled = false;
277+
278+
if (_intrPin < 0 && !_scheduled)
279+
{
280+
_scheduled = schedule_recurrent_function_us(
277281
[&]()
278282
{
279283
this->handlePackets();
284+
if (!_started)
285+
{
286+
_scheduled = false;
287+
return false;
288+
}
280289
return true;
281290
},
282-
100))
283-
{
284-
netif_remove(&_netif);
285-
return false;
291+
100);
292+
if (!_scheduled)
293+
{
294+
netif_remove(&_netif);
295+
return false;
296+
}
286297
}
287298

288299
return true;
289300
}
290301

302+
template<class RawDev>
303+
void LwipIntfDev<RawDev>::end()
304+
{
305+
netif_remove(&_netif);
306+
ip_addr_copy(_netif.ip_addr, ip_addr_any); // to allow DHCP at next begin
307+
ip_addr_copy(_netif.netmask, ip_addr_any);
308+
ip_addr_copy(_netif.gw, ip_addr_any);
309+
_started = false;
310+
RawDev::end();
311+
}
312+
291313
template<class RawDev>
292314
wl_status_t LwipIntfDev<RawDev>::status()
293315
{

0 commit comments

Comments
 (0)