From 6515190124d181a2be5140f530d987d845c5aa51 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 11 May 2020 17:23:20 -0500 Subject: [PATCH] fixes #1046 --- WiFiManager.cpp | 12 +++++++----- WiFiManager.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 08e61ec..b2e97eb 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -206,9 +206,10 @@ WiFiManager::~WiFiManager() { } // @todo remove event - // #ifdef ESP32 - // WiFi.removeEvent(std::bind(&WiFiManager::WiFiEvent,this)); - // #endif + // WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); + #ifdef ESP32 + WiFi.removeEvent(wm_event_id); + #endif DEBUG_WM(DEBUG_DEV,F("unloading")); } @@ -2898,8 +2899,9 @@ String WiFiManager::WiFi_psk(bool persistent) const { void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ if(!_hasBegun){ // DEBUG_WM(DEBUG_VERBOSE,"[ERROR] WiFiEvent, not ready"); + Serial.println("[ERROR] wm not ready"); return; - } + } // DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event); if(event == SYSTEM_EVENT_STA_DISCONNECTED){ DEBUG_WM(DEBUG_VERBOSE,"[EVENT] WIFI_REASON:",info.disconnected.reason); @@ -2927,7 +2929,7 @@ void WiFiManager::WiFi_autoReconnect(){ // @todo move to seperate method, used for event listener now DEBUG_WM(DEBUG_VERBOSE,"ESP32 event handler enabled"); using namespace std::placeholders; - WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); + wm_event_id = WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); // } #endif } diff --git a/WiFiManager.h b/WiFiManager.h index 87e136e..b5189af 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -134,7 +134,6 @@ class WiFiManagerParameter { int _length; int _labelPlacement; const char *_customHTML; - friend class WiFiManager; }; @@ -355,6 +354,7 @@ class WiFiManager uint16_t _httpPort = 80; // port for webserver #ifdef ESP32 + wifi_event_id_t wm_event_id; static uint8_t _lastconxresulttmp; // tmp var for esp32 callback #endif