From 55d5efe866a056377dc5ee87cebdfb372bb29e3a Mon Sep 17 00:00:00 2001 From: Juraj Andrassy Date: Thu, 9 Nov 2023 07:19:33 +0100 Subject: [PATCH] LwipIntfDev - method end() to enable repeated begin --- cores/esp8266/LwipIntfDev.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/LwipIntfDev.h b/cores/esp8266/LwipIntfDev.h index 389376c976..8ace91edc7 100644 --- a/cores/esp8266/LwipIntfDev.h +++ b/cores/esp8266/LwipIntfDev.h @@ -68,6 +68,7 @@ class LwipIntfDev: public LwipIntf, public RawDev // default mac-address is inferred from esp8266's STA interface boolean begin(const uint8_t* macAddress = nullptr, const uint16_t mtu = DEFAULT_MTU); + void end(); const netif* getNetIf() const { @@ -138,6 +139,7 @@ class LwipIntfDev: public LwipIntf, public RawDev int8_t _intrPin; uint8_t _macAddress[6]; bool _started; + bool _scheduled; bool _default; }; @@ -272,22 +274,41 @@ boolean LwipIntfDev::begin(const uint8_t* macAddress, const uint16_t mtu } } - if (_intrPin < 0 - && !schedule_recurrent_function_us( + if (_intrPin < 0 && !_scheduled) + { + _scheduled = schedule_recurrent_function_us( [&]() { + if (!_started) + { + _scheduled = false; + return false; + } this->handlePackets(); return true; }, - 100)) - { - netif_remove(&_netif); - return false; + 100); + if (!_scheduled) + { + netif_remove(&_netif); + return false; + } } return true; } +template +void LwipIntfDev::end() +{ + netif_remove(&_netif); + ip_addr_copy(_netif.ip_addr, ip_addr_any); // to allow DHCP at next begin + ip_addr_copy(_netif.netmask, ip_addr_any); + ip_addr_copy(_netif.gw, ip_addr_any); + _started = false; + RawDev::end(); +} + template wl_status_t LwipIntfDev::status() {