Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function to request the status of the Access Point with a limit uptime setting #1607

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
DEBUG_WM(F("AutoConnect"));
#endif

_WifiAP_active = false;

// bool wifiIsSaved = getWiFiIsSaved();

#ifdef ESP32
Expand Down Expand Up @@ -461,6 +463,7 @@ bool WiFiManager::setupHostname(bool restart){

// CONFIG PORTAL
bool WiFiManager::startAP(){
_WifiAP_active = true;
bool ret = true;
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(F("StartAP with SSID: "),_apName);
Expand Down Expand Up @@ -574,6 +577,13 @@ void WiFiManager::stopWebPortal() {
shutdownConfigPortal();
}

bool WiFiManager::WifiAP_active(int max_uptime_minutes){
if((millis()-_startconn) < (max_uptime_minutes * 60000)){
return (_WifiAP_active);
}
return false;
}

boolean WiFiManager::configPortalHasTimeout(){
if(!configPortalActive) return false;
uint16_t logintvl = 30000; // how often to emit timeing out counter logging
Expand Down Expand Up @@ -1329,6 +1339,8 @@ void WiFiManager::handleRoot() {
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Root"));
#endif

_WifiAP_active = true;
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
handleRequest();
String page = getHTTPHead(_title); // @token options @todo replace options with title
Expand Down Expand Up @@ -2312,6 +2324,7 @@ void WiFiManager::handleExit() {
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Exit"));
#endif
_WifiAP_active = false;
handleRequest();
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
page += FPSTR(S_exiting); // @token exiting
Expand Down Expand Up @@ -2440,6 +2453,7 @@ void WiFiManager::stopCaptivePortal(){
// HTTPD CALLBACK, handle close, stop captive portal, if not enabled undefined
void WiFiManager::handleClose(){
DEBUG_WM(DEBUG_VERBOSE,F("Disabling Captive Portal"));
_WifiAP_active = false;
stopCaptivePortal();
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP close"));
Expand Down
4 changes: 4 additions & 0 deletions WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ class WiFiManager
// get hostname helper
String getWiFiHostname();

// indicate if AP is currently in use
bool WifiAP_active(int max_uptime_minutes);


std::unique_ptr<DNSServer> dnsServer;

Expand Down Expand Up @@ -553,6 +556,7 @@ class WiFiManager
// on some conn failure modes will add delays and many retries to work around esp and ap bugs, ie, anti de-auth protections
// https://github.com/tzapu/WiFiManager/issues/1067
bool _allowExit = true; // allow exit in nonblocking, else user exit/abort calls will be ignored including cptimeout
bool _WifiAP_active = false;

#ifdef ESP32
wifi_event_id_t wm_event_id = 0;
Expand Down