Skip to content

Commit 757dda7

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

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

cores/esp8266/LwipIntfDev.h

+27-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,42 @@ 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+
_scheduled = false;
286+
return false;
287+
}
280288
return true;
281289
},
282-
100))
283-
{
284-
netif_remove(&_netif);
285-
return false;
290+
100);
291+
if (!_scheduled)
292+
{
293+
netif_remove(&_netif);
294+
return false;
295+
}
286296
}
287297

288298
return true;
289299
}
290300

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

0 commit comments

Comments
 (0)