@@ -68,6 +68,7 @@ class LwipIntfDev: public LwipIntf, public RawDev
68
68
69
69
// default mac-address is inferred from esp8266's STA interface
70
70
boolean begin (const uint8_t * macAddress = nullptr , const uint16_t mtu = DEFAULT_MTU);
71
+ void end ();
71
72
72
73
const netif* getNetIf () const
73
74
{
@@ -170,6 +171,7 @@ class LwipIntfDev: public LwipIntf, public RawDev
170
171
int8_t _intrPin;
171
172
uint8_t _macAddress[6 ];
172
173
bool _started;
174
+ bool _scheduled;
173
175
bool _default;
174
176
};
175
177
@@ -261,6 +263,7 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
261
263
if (!netif_add (&_netif, ip_2_ip4 (&ip_addr), ip_2_ip4 (&netmask), ip_2_ip4 (&gw), this ,
262
264
netif_init_s, ethernet_input))
263
265
{
266
+ RawDev::end ();
264
267
return false ;
265
268
}
266
269
@@ -274,10 +277,11 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
274
277
break ;
275
278
276
279
case ERR_IF:
280
+ RawDev::end ();
277
281
return false ;
278
282
279
283
default :
280
- netif_remove (&_netif );
284
+ end ( );
281
285
return false ;
282
286
}
283
287
}
@@ -304,22 +308,41 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
304
308
}
305
309
}
306
310
307
- if (_intrPin < 0
308
- && !schedule_recurrent_function_us (
311
+ if (_intrPin < 0 && !_scheduled)
312
+ {
313
+ _scheduled = schedule_recurrent_function_us (
309
314
[&]()
310
315
{
316
+ if (!_started)
317
+ {
318
+ _scheduled = false ;
319
+ return false ;
320
+ }
311
321
this ->handlePackets ();
312
322
return true ;
313
323
},
314
- 100 ))
315
- {
316
- netif_remove (&_netif);
317
- return false ;
324
+ 100 );
325
+ if (!_scheduled)
326
+ {
327
+ end ();
328
+ return false ;
329
+ }
318
330
}
319
331
320
332
return true ;
321
333
}
322
334
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
+
323
346
template <class RawDev >
324
347
wl_status_t LwipIntfDev<RawDev>::status()
325
348
{
0 commit comments