diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 542a7e2a218..4c0b8cbbcfb 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -136,7 +136,7 @@ ETHClass::ETHClass(uint8_t eth_index) _pin_mcd(-1), _pin_mdio(-1), _pin_power(-1), _pin_rmii_clock(-1) #endif /* CONFIG_ETH_USE_ESP32_EMAC */ , - _task_stack_size(4096) { + _task_stack_size(4096), _eth_connected_event_handle(0) { } ETHClass::~ETHClass() {} @@ -359,7 +359,7 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i /* attach to receive events */ initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index)); - Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); + _eth_connected_event_handle = Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); ret = esp_eth_start(_eth_handle); if (ret != ESP_OK) { @@ -849,7 +849,7 @@ bool ETHClass::beginSPI( perimanSetPinBusExtraType(_pin_rst, "ETH_RST"); } - Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); + _eth_connected_event_handle = Network.onSysEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); return true; @@ -885,7 +885,8 @@ static bool empty_ethDetachBus(void *bus_pointer) { void ETHClass::end(void) { - Network.removeEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED); + Network.removeEvent(_eth_connected_event_handle); + _eth_connected_event_handle = 0; if (_eth_handle != NULL) { if (esp_eth_stop(_eth_handle) != ESP_OK) { diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index 891863e34bf..1995fc77a77 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -247,6 +247,7 @@ class ETHClass : public NetworkInterface { int8_t _pin_rmii_clock; #endif /* CONFIG_ETH_USE_ESP32_EMAC */ size_t _task_stack_size; + network_event_handle_t _eth_connected_event_handle; static bool ethDetachBus(void *bus_pointer); bool beginSPI( diff --git a/libraries/PPP/src/PPP.cpp b/libraries/PPP/src/PPP.cpp index 77b70d3969c..87fee6920c3 100644 --- a/libraries/PPP/src/PPP.cpp +++ b/libraries/PPP/src/PPP.cpp @@ -152,7 +152,8 @@ esp_modem_dce_t *PPPClass::handle() const { PPPClass::PPPClass() : _dce(NULL), _pin_tx(-1), _pin_rx(-1), _pin_rts(-1), _pin_cts(-1), _flow_ctrl(ESP_MODEM_FLOW_CONTROL_NONE), _pin_rst(-1), _pin_rst_act_low(true), - _pin_rst_delay(200), _pin(NULL), _apn(NULL), _rx_buffer_size(4096), _tx_buffer_size(512), _mode(ESP_MODEM_MODE_COMMAND), _uart_num(UART_NUM_1) {} + _pin_rst_delay(200), _pin(NULL), _apn(NULL), _rx_buffer_size(4096), _tx_buffer_size(512), _mode(ESP_MODEM_MODE_COMMAND), _uart_num(UART_NUM_1), + _ppp_event_handle(0) {} PPPClass::~PPPClass() {} @@ -360,7 +361,7 @@ bool PPPClass::begin(ppp_modem_model_t model, uint8_t uart_num, int baud_rate) { } } - Network.onSysEvent(onPppArduinoEvent); + _ppp_event_handle = Network.onSysEvent(onPppArduinoEvent); setStatusBits(ESP_NETIF_STARTED_BIT); arduino_event_t arduino_event; @@ -402,7 +403,8 @@ void PPPClass::end(void) { } _esp_modem = NULL; - Network.removeEvent(onPppArduinoEvent); + Network.removeEvent(_ppp_event_handle); + _ppp_event_handle = 0; if (_dce != NULL) { esp_modem_destroy(_dce); diff --git a/libraries/PPP/src/PPP.h b/libraries/PPP/src/PPP.h index b8e1f7ad56f..b317f52aefc 100644 --- a/libraries/PPP/src/PPP.h +++ b/libraries/PPP/src/PPP.h @@ -108,6 +108,7 @@ class PPPClass : public NetworkInterface { int _tx_buffer_size; esp_modem_dce_mode_t _mode; uint8_t _uart_num; + network_event_handle_t _ppp_event_handle; static bool pppDetachBus(void *bus_pointer); }; diff --git a/libraries/WiFi/src/AP.cpp b/libraries/WiFi/src/AP.cpp index b713a6d3901..0e7839764ea 100644 --- a/libraries/WiFi/src/AP.cpp +++ b/libraries/WiFi/src/AP.cpp @@ -148,7 +148,7 @@ void APClass::_onApEvent(int32_t event_id, void *event_data) { } } -APClass::APClass() { +APClass::APClass() : _wifi_ap_event_handle(0) { _ap_network_if = this; } @@ -163,7 +163,7 @@ bool APClass::onEnable() { return false; } if (_esp_netif == NULL) { - Network.onSysEvent(_onApArduinoEvent); + _wifi_ap_event_handle = Network.onSysEvent(_onApArduinoEvent); _esp_netif = get_esp_interface_netif(ESP_IF_WIFI_AP); /* attach to receive events */ initNetif(ESP_NETIF_ID_AP); @@ -172,7 +172,8 @@ bool APClass::onEnable() { } bool APClass::onDisable() { - Network.removeEvent(_onApArduinoEvent); + Network.removeEvent(_wifi_ap_event_handle); + _wifi_ap_event_handle = 0; // we just set _esp_netif to NULL here, so destroyNetif() does not try to destroy it. // That would be done by WiFi.enableAP(false) if STA is not enabled, or when it gets disabled _esp_netif = NULL; diff --git a/libraries/WiFi/src/STA.cpp b/libraries/WiFi/src/STA.cpp index 547a27d1c47..84258589b28 100644 --- a/libraries/WiFi/src/STA.cpp +++ b/libraries/WiFi/src/STA.cpp @@ -228,7 +228,8 @@ void STAClass::_onStaEvent(int32_t event_id, void *event_data) { } STAClass::STAClass() - : _minSecurity(WIFI_AUTH_WPA2_PSK), _scanMethod(WIFI_FAST_SCAN), _sortMethod(WIFI_CONNECT_AP_BY_SIGNAL), _autoReconnect(true), _status(WL_STOPPED) { + : _minSecurity(WIFI_AUTH_WPA2_PSK), _scanMethod(WIFI_FAST_SCAN), _sortMethod(WIFI_CONNECT_AP_BY_SIGNAL), _autoReconnect(true), _status(WL_STOPPED), + _wifi_sta_event_handle(0) { _sta_network_if = this; } @@ -276,14 +277,15 @@ bool STAClass::onEnable() { return false; } /* attach to receive events */ - Network.onSysEvent(_onStaArduinoEvent); + _wifi_sta_event_handle = Network.onSysEvent(_onStaArduinoEvent); initNetif(ESP_NETIF_ID_STA); } return true; } bool STAClass::onDisable() { - Network.removeEvent(_onStaArduinoEvent); + Network.removeEvent(_wifi_sta_event_handle); + _wifi_sta_event_handle = 0; // we just set _esp_netif to NULL here, so destroyNetif() does not try to destroy it. // That would be done by WiFi.enableSTA(false) if AP is not enabled, or when it gets disabled _esp_netif = NULL; diff --git a/libraries/WiFi/src/WiFiAP.h b/libraries/WiFi/src/WiFiAP.h index e80f91fa26c..540ec87f44f 100644 --- a/libraries/WiFi/src/WiFiAP.h +++ b/libraries/WiFi/src/WiFiAP.h @@ -60,6 +60,8 @@ class APClass : public NetworkInterface { void _onApEvent(int32_t event_id, void *event_data); protected: + network_event_handle_t _wifi_ap_event_handle; + size_t printDriverInfo(Print &out) const; friend class WiFiGenericClass; diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index 3c8adbd8502..6063eae7968 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -95,6 +95,7 @@ class STAClass : public NetworkInterface { wifi_sort_method_t _sortMethod; bool _autoReconnect; wl_status_t _status; + network_event_handle_t _wifi_sta_event_handle; size_t printDriverInfo(Print &out) const;