Skip to content

Commit 8587f46

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

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

cores/esp8266/LwipIntfDev.h

+29-10
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
{
@@ -138,6 +139,7 @@ class LwipIntfDev: public LwipIntf, public RawDev
138139
int8_t _intrPin;
139140
uint8_t _macAddress[6];
140141
bool _started;
142+
bool _scheduled;
141143
bool _default;
142144
};
143145

@@ -272,22 +274,39 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
272274
}
273275
}
274276

275-
if (_intrPin < 0
276-
&& !schedule_recurrent_function_us(
277-
[&]()
278-
{
279-
this->handlePackets();
280-
return true;
281-
},
282-
100))
277+
if (_intrPin < 0 && !_scheduled)
283278
{
284-
netif_remove(&_netif);
285-
return false;
279+
if (schedule_recurrent_function_us(
280+
[&]()
281+
{
282+
this->handlePackets();
283+
return true;
284+
},
285+
100))
286+
{
287+
_scheduled = true;
288+
}
289+
else
290+
{
291+
netif_remove(&_netif);
292+
return false;
293+
}
286294
}
287295

288296
return true;
289297
}
290298

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

0 commit comments

Comments
 (0)