@@ -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 {
@@ -170,6 +171,7 @@ class LwipIntfDev: public LwipIntf, public RawDev
170171 int8_t _intrPin;
171172 uint8_t _macAddress[6 ];
172173 bool _started;
174+ bool _scheduled;
173175 bool _default;
174176};
175177
@@ -261,6 +263,7 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
261263 if (!netif_add (&_netif, ip_2_ip4 (&ip_addr), ip_2_ip4 (&netmask), ip_2_ip4 (&gw), this ,
262264 netif_init_s, ethernet_input))
263265 {
266+ RawDev::end ();
264267 return false ;
265268 }
266269
@@ -274,10 +277,11 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
274277 break ;
275278
276279 case ERR_IF:
280+ RawDev::end ();
277281 return false ;
278282
279283 default :
280- netif_remove (&_netif );
284+ end ( );
281285 return false ;
282286 }
283287 }
@@ -304,22 +308,41 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
304308 }
305309 }
306310
307- if (_intrPin < 0
308- && !schedule_recurrent_function_us (
311+ if (_intrPin < 0 && !_scheduled)
312+ {
313+ _scheduled = schedule_recurrent_function_us (
309314 [&]()
310315 {
316+ if (!_started)
317+ {
318+ _scheduled = false ;
319+ return false ;
320+ }
311321 this ->handlePackets ();
312322 return true ;
313323 },
314- 100 ))
315- {
316- netif_remove (&_netif);
317- return false ;
324+ 100 );
325+ if (!_scheduled)
326+ {
327+ end ();
328+ return false ;
329+ }
318330 }
319331
320332 return true ;
321333}
322334
335+ template <class RawDev >
336+ void LwipIntfDev<RawDev>::end()
337+ {
338+ netif_remove (&_netif);
339+ ip_addr_copy (_netif.ip_addr , ip_addr_any); // to allow DHCP at next begin
340+ ip_addr_copy (_netif.netmask , ip_addr_any);
341+ ip_addr_copy (_netif.gw , ip_addr_any);
342+ _started = false ;
343+ RawDev::end ();
344+ }
345+
323346template <class RawDev >
324347wl_status_t LwipIntfDev<RawDev>::status()
325348{
0 commit comments