From 5024c9ca38a56b1b5b5102ecf5f46c0f9d34219a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADn?= Date: Thu, 24 Oct 2019 10:00:36 +0200 Subject: [PATCH 1/2] Callbackless save configuration notification --- ESPAsyncWiFiManager.cpp | 13 ++++++++++--- ESPAsyncWiFiManager.h | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ESPAsyncWiFiManager.cpp b/ESPAsyncWiFiManager.cpp index 4455258..4c19e78 100644 --- a/ESPAsyncWiFiManager.cpp +++ b/ESPAsyncWiFiManager.cpp @@ -355,6 +355,7 @@ void AsyncWiFiManager::startConfigPortalModeless(char const *apName, char const _modeless =true; _apName = apName; _apPassword = apPassword; + _shouldSaveConfig = false; /* AJS - do we want this? @@ -370,11 +371,12 @@ void AsyncWiFiManager::startConfigPortalModeless(char const *apName, char const DEBUG_WM(F("IP Address:")); DEBUG_WM(WiFi.localIP()); //connected - // call the callback! - if ( _savecallback != NULL) { + // call the callback! // gmag11: Should callback be called here? + //_shouldSaveConfig = true; + /*if ( _savecallback != NULL) { //todo: check if any custom parameters actually exist, and check if they really changed maybe _savecallback(); - } + }*/ } @@ -428,6 +430,7 @@ void AsyncWiFiManager::criticalLoop(){ // alanswx - should we have a config to decide if we should shut down AP? // WiFi.mode(WIFI_STA); //notify that configuration has changed and any optional parameters should be saved + _shouldSaveConfig = true; if ( _savecallback != NULL) { //todo: check if any custom parameters actually exist, and check if they really changed maybe _savecallback(); @@ -439,6 +442,7 @@ void AsyncWiFiManager::criticalLoop(){ if (_shouldBreakAfterConfig) { //flag set to exit after config after trying to connect //notify that configuration has changed and any optional parameters should be saved + _shouldSaveConfig = true; if ( _savecallback != NULL) { //todo: check if any custom parameters actually exist, and check if they really changed maybe _savecallback(); @@ -462,6 +466,7 @@ boolean AsyncWiFiManager::startConfigPortal(char const *apName, char const *apP WiFi.mode(WIFI_AP_STA); DEBUG_WM("SET AP STA"); + _shouldSaveConfig = false; _apName = apName; _apPassword = apPassword; @@ -505,6 +510,7 @@ boolean AsyncWiFiManager::startConfigPortal(char const *apName, char const *apP //connected WiFi.mode(WIFI_STA); //notify that configuration has changed and any optional parameters should be saved + _shouldSaveConfig = true; if ( _savecallback != NULL) { //todo: check if any custom parameters actually exist, and check if they really changed maybe _savecallback(); @@ -533,6 +539,7 @@ boolean AsyncWiFiManager::startConfigPortal(char const *apName, char const *apP } if (_shouldBreakAfterConfig) { + _shouldSaveConfig = true; //flag set to exit after config after trying to connect //notify that configuration has changed and any optional parameters should be saved if ( _savecallback != NULL) { diff --git a/ESPAsyncWiFiManager.h b/ESPAsyncWiFiManager.h index db30a57..3e54790 100644 --- a/ESPAsyncWiFiManager.h +++ b/ESPAsyncWiFiManager.h @@ -145,7 +145,6 @@ class AsyncWiFiManager //configuration portal (ESP as access point) is running [default true/on] void setTryConnectDuringConfigPortal(boolean v); - void setDebugOutput(boolean debug); //defaults to not showing anything under 8% signal quality if called void setMinimumSignalQuality(int quality = 8); @@ -157,6 +156,10 @@ class AsyncWiFiManager void setAPCallback( void (*func)(AsyncWiFiManager*) ); //called when settings have been changed and connection was successful void setSaveConfigCallback( void (*func)(void) ); + //gets condition that signals if configuration should be saved + boolean shouldSaveConfig () { + return _shouldSaveConfig; + } //adds a custom parameter void addParameter(AsyncWiFiManagerParameter *p); //if this is set, it will exit after config, even if connection is unsucessful. @@ -260,6 +263,7 @@ class AsyncWiFiManager void (*_apcallback)(AsyncWiFiManager*) = NULL; void (*_savecallback)(void) = NULL; + boolean _shouldSaveConfig = false; AsyncWiFiManagerParameter* _params[WIFI_MANAGER_MAX_PARAMS]; From 96963ed0bac8b112a8012d62617c258e3294a079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADn?= Date: Thu, 24 Oct 2019 10:07:20 +0200 Subject: [PATCH 2/2] Revert callback disabling --- ESPAsyncWiFiManager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ESPAsyncWiFiManager.cpp b/ESPAsyncWiFiManager.cpp index 4c19e78..b6cd3ed 100644 --- a/ESPAsyncWiFiManager.cpp +++ b/ESPAsyncWiFiManager.cpp @@ -371,12 +371,12 @@ void AsyncWiFiManager::startConfigPortalModeless(char const *apName, char const DEBUG_WM(F("IP Address:")); DEBUG_WM(WiFi.localIP()); //connected - // call the callback! // gmag11: Should callback be called here? - //_shouldSaveConfig = true; - /*if ( _savecallback != NULL) { + // call the callback! + _shouldSaveConfig = true; + if ( _savecallback != NULL) { //todo: check if any custom parameters actually exist, and check if they really changed maybe _savecallback(); - }*/ + } }