Skip to content

Commit 55d5efe

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

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
{
@@ -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,41 @@ 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+
if (_intrPin < 0 && !_scheduled)
278+
{
279+
_scheduled = schedule_recurrent_function_us(
277280
[&]()
278281
{
282+
if (!_started)
283+
{
284+
_scheduled = false;
285+
return false;
286+
}
279287
this->handlePackets();
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)