Looking for a way to track if the portal is up or not #543
Replies: 9 comments 2 replies
-
@softwaregravy Your question may lead to an AutoConnect enhancement. I would like to move this topic to Discussions and discuss specific implementations there. |
Beta Was this translation helpful? Give feedback.
-
I think the easiest implementation might be for AutoConnect to keep track of the state itself. With a simple boolean. The question is where to set this. I might suggest setting to true in
Then we just expose this via a simple boolean check |
Beta Was this translation helpful? Give feedback.
-
For illustrative/discussion purposes: #545 I found that the cleanest place to integrate the checks was in the DNS control. I'm testing this out in my project. |
Beta Was this translation helpful? Give feedback.
-
@softwaregravy Thanks for your preliminary survey and PR.
Yes, you are correct. Captive Portal - i.e., just a spoofed response to a DNS lookup for Internet connection verification that occurs on a new connection attempt from the client device; it needs a DNS server and SoftAP to work, so if we can detect that one or the other is missing, I think we can fulfill your request. So, about your approach as follows:
I believe your PR #545 meets the above requirements but would suggest adding further detection conditions. It is an approach that allows the isPortalAvailable function to determine state at a point in time, rather than a DNS and SoftAP state trace on AutoConnect itself. In AutoConnectCore<T>::isPortalAvailable without
bool isPortalAvailable(void) {
bool state = WiFi.getMode() & WIFI_MODE_AP;
state &= (WiFi.softAPIP() == _apConfig.apip);
state &= (_dnsServer.get() != nullptr);
return state;
} How about this? |
Beta Was this translation helpful? Give feedback.
-
I understand your concern. The On other hand, stopping SoftAP using So, I think it is probably okay. |
Beta Was this translation helpful? Give feedback.
-
Seems solid. 👍 |
Beta Was this translation helpful? Give feedback.
-
@softwaregravy Oh, yes. A little bonus: If you build by giving the |
Beta Was this translation helpful? Give feedback.
-
The boolean check appears to be working well. 👍 The check-mark has limited utility for me. We don't connect to the weberver unless the portal is active, so it's just always checked. Thank you! PS. I tested on a local implementation by copying your suggestion. Didn't actually test your patch branch. |
Beta Was this translation helpful? Give feedback.
-
This feature was released in AutoConnect v1.4.1. |
Beta Was this translation helpful? Give feedback.
-
I'm looking for a way to determine if the portal is available or not from code. We'd like to display an icon/change visible behavior if the portal is available.
I've hooked in to the
onDetect
callback for starting the portal, and then we have theonConnect
. With a successful connection, my code works as I put aportal_available = true
in the first callback, and aportal_available = false
in the second. However, a_stopPortal()
call happens for a few other reasons like timeout/disconnect or reset. I'm not seeing any way to get a hook to know we shut down.One avenue I've looked into is the WifiClient on the WebServer, but this only works if someone has actually connected. I'm looking for if the portal is available at all.
Webserver.client()
WifiClient.connected()
I also looked into
WebServer
which has aWifiServer
underneath it which does have anoperator bool()
which I think would give me what I'm looking for. But I don't see a good way to get to that object fromAutoConnect
orWebServer
.WebServer
doesn't seem to expose this instance at all.Thoughts?
An alternative would be to ask for another callback on AutoConnect probably from inside
_stopPortal()
, or for AutoConnect itself to keep track of the status and provide a bool method to check.Thoughts on this?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions