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

Make portal availability accessible #545

Open
wants to merge 4 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/AutoConnectCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class AutoConnectCore {
template<typename U = AUTOCONNECT_APPLIED_FILECLASS>
bool restoreCredential(const char* filename = "/" AC_IDENTIFIER, U& fs = AUTOCONNECT_APPLIED_FILESYSTEM);

bool portalAvailable() { return _portalAvailable; }

protected:
typedef enum {
AC_RECONNECT_SET,
Expand Down Expand Up @@ -160,6 +162,8 @@ class AutoConnectCore {
#ifdef ARDUINO_ARCH_ESP32
WiFiEventId_t _disconnectEventId = -1; /**< STA disconnection event handler registered id */
#endif
bool _portalAvailable = false; /** will be true when the portal is available **/

/** Only available with ticker enabled */
std::unique_ptr<AutoConnectTicker> _ticker;

Expand Down
2 changes: 2 additions & 0 deletions src/AutoConnectCoreImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ template<typename T>
void AutoConnectCore<T>::_startDNSServer(void) {
// Boot DNS server, set up for captive portal redirection.
if (!_dnsServer) {
_portalAvailable = true;
_dnsServer.reset(new DNSServer());
_dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
_dnsServer->start(AUTOCONNECT_DNSPORT, "*", WiFi.softAPIP());
Expand All @@ -1054,6 +1055,7 @@ void AutoConnectCore<T>::_startDNSServer(void) {
template<typename T>
void AutoConnectCore<T>::_stopDNSServer(void) {
if (_dnsServer) {
_portalAvailable = false;
_dnsServer->stop();
_dnsServer.reset();
AC_DBG("DNS server stopped\n");
Expand Down