Supports a onConnect exit

enhance/v120
Hieromon Ikasamo 5 years ago
parent e9fda58180
commit 2437d51d29
  1. 13
      src/AutoConnect.cpp
  2. 3
      src/AutoConnect.h

@ -649,6 +649,14 @@ bool AutoConnect::on(const String& uri, const AuxHandlerFunctionT handler, AutoC
return false; return false;
} }
/**
* Register the exit routine that is being called when WiFi connected.
* @param fn A function of the exit routine.
*/
void AutoConnect::onConnect(ConnectExit_ft fn) {
_onConnectExit = fn;
}
/** /**
* Register the exit routine for the starting captive portal. * Register the exit routine for the starting captive portal.
* @param fn A function of the exit routine. * @param fn A function of the exit routine.
@ -1115,6 +1123,11 @@ wl_status_t AutoConnect::_waitForConnect(unsigned long timeout) {
delay(300); delay(300);
} }
AC_DBG_DUMB("%s IP:%s\n", wifiStatus == WL_CONNECTED ? "established" : "time out", WiFi.localIP().toString().c_str()); AC_DBG_DUMB("%s IP:%s\n", wifiStatus == WL_CONNECTED ? "established" : "time out", WiFi.localIP().toString().c_str());
if (WiFi.status() == WL_CONNECTED)
if (_onConnectExit) {
IPAddress localIP = WiFi.localIP();
_onConnectExit(localIP);
}
return wifiStatus; return wifiStatus;
} }

@ -262,7 +262,9 @@ class AutoConnect {
#endif // !AUTOCONNECT_USE_JSON #endif // !AUTOCONNECT_USE_JSON
typedef std::function<bool(IPAddress&)> DetectExit_ft; typedef std::function<bool(IPAddress&)> DetectExit_ft;
typedef std::function<void(IPAddress&)> ConnectExit_ft;
void onDetect(DetectExit_ft fn); void onDetect(DetectExit_ft fn);
void onConnect(ConnectExit_ft fn);
void onNotFound(WebServerClass::THandlerFunction fn); void onNotFound(WebServerClass::THandlerFunction fn);
protected: protected:
@ -310,6 +312,7 @@ class AutoConnect {
static uint32_t _getFlashChipRealSize(void); static uint32_t _getFlashChipRealSize(void);
static String _toMACAddressString(const uint8_t mac[]); static String _toMACAddressString(const uint8_t mac[]);
static unsigned int _toWiFiQuality(int32_t rssi); static unsigned int _toWiFiQuality(int32_t rssi);
ConnectExit_ft _onConnectExit;
DetectExit_ft _onDetectExit; DetectExit_ft _onDetectExit;
WebServerClass::THandlerFunction _notFoundHandler; WebServerClass::THandlerFunction _notFoundHandler;
size_t _freeHeapSize; size_t _freeHeapSize;

Loading…
Cancel
Save