@@ -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
{
@@ -138,6 +139,7 @@ class LwipIntfDev: public LwipIntf, public RawDev
138
139
int8_t _intrPin;
139
140
uint8_t _macAddress[6 ];
140
141
bool _started;
142
+ bool _scheduled;
141
143
bool _default;
142
144
};
143
145
@@ -229,6 +231,7 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
229
231
if (!netif_add (&_netif, ip_2_ip4 (&ip_addr), ip_2_ip4 (&netmask), ip_2_ip4 (&gw), this ,
230
232
netif_init_s, ethernet_input))
231
233
{
234
+ RawDev::end ();
232
235
return false ;
233
236
}
234
237
@@ -242,10 +245,11 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
242
245
break ;
243
246
244
247
case ERR_IF:
248
+ RawDev::end ();
245
249
return false ;
246
250
247
251
default :
248
- netif_remove (&_netif );
252
+ end ( );
249
253
return false ;
250
254
}
251
255
}
@@ -272,22 +276,41 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
272
276
}
273
277
}
274
278
275
- if (_intrPin < 0
276
- && !schedule_recurrent_function_us (
279
+ if (_intrPin < 0 && !_scheduled)
280
+ {
281
+ _scheduled = schedule_recurrent_function_us (
277
282
[&]()
278
283
{
284
+ if (!_started)
285
+ {
286
+ _scheduled = false ;
287
+ return false ;
288
+ }
279
289
this ->handlePackets ();
280
290
return true ;
281
291
},
282
- 100 ))
283
- {
284
- netif_remove (&_netif);
285
- return false ;
292
+ 100 );
293
+ if (!_scheduled)
294
+ {
295
+ end ();
296
+ return false ;
297
+ }
286
298
}
287
299
288
300
return true ;
289
301
}
290
302
303
+ template <class RawDev >
304
+ void LwipIntfDev<RawDev>::end()
305
+ {
306
+ netif_remove (&_netif);
307
+ ip_addr_copy (_netif.ip_addr , ip_addr_any); // to allow DHCP at next begin
308
+ ip_addr_copy (_netif.netmask , ip_addr_any);
309
+ ip_addr_copy (_netif.gw , ip_addr_any);
310
+ _started = false ;
311
+ RawDev::end ();
312
+ }
313
+
291
314
template <class RawDev >
292
315
wl_status_t LwipIntfDev<RawDev>::status()
293
316
{
0 commit comments