Fixed Ticker discontinue at AutoConnect::begin ends

enhance/v120
Hieromon Ikasamo 5 years ago
parent 09170d7cac
commit 3618841f13
  1. 29
      src/AutoConnect.cpp
  2. 4
      src/AutoConnectDefs.h

@ -3,7 +3,7 @@
* @file AutoConnect.cpp
* @author hieromon@gmail.com
* @version 1.2.0
* @date 2020-04-22
* @date 2020-04-23
* @copyright MIT license.
*/
@ -257,11 +257,6 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long
if (!_responsePage)
_startWebServer();
// Stop ticker
if (cs)
if (_ticker)
_ticker->stop();
return cs;
}
@ -524,7 +519,7 @@ void AutoConnect::handleRequest(void) {
strncat(password_c, reinterpret_cast<const char*>(_credential.password), sizeof(password_c) - 1);
AC_DBG("Attempt:%s Ch(%d)\n", ssid_c, (int)ch);
WiFi.begin(ssid_c, password_c, ch);
if (_waitForConnect(_connectTimeout) == WL_CONNECTED) {
if ((_rsConnect = _waitForConnect(_connectTimeout)) == WL_CONNECTED) {
if (WiFi.BSSID() != NULL) {
memcpy(_credential.bssid, WiFi.BSSID(), sizeof(station_config_t::bssid));
_currentHostIP = WiFi.localIP();
@ -556,12 +551,14 @@ void AutoConnect::handleRequest(void) {
else {
_currentHostIP = WiFi.softAPIP();
_redirectURI = String(F(AUTOCONNECT_URI_FAIL));
_rsConnect = WiFi.status();
_disconnectWiFi(false);
while (WiFi.status() != WL_IDLE_STATUS && WiFi.status() != WL_DISCONNECTED) {
delay(1);
yield();
}
// Restore the ticker
if (_ticker && WiFi.getMode() == WIFI_AP_STA)
_ticker->start(AUTOCONNECT_FLICKER_PERIODAP, (uint8_t)AUTOCONNECT_FLICKER_WIDTHAP);
}
_rfConnect = false;
}
@ -619,6 +616,12 @@ void AutoConnect::handleRequest(void) {
// Reflect the menu display specifier from AutoConnectConfig to AutoConnectOTA page
_ota->menu(_apConfig.menuItems & AC_MENUITEM_UPDATE);
}
// Post-process for ticker
if (_ticker) {
if (WiFi.status() == WL_CONNECTED)
_ticker->stop();
}
}
/**
@ -1212,6 +1215,16 @@ void AutoConnect::_disconnectWiFi(bool wifiOff) {
delay(1);
yield();
}
// Restart the ticker to indicate that ESP module into the disconnected state.
if (_ticker) {
uint32_t tc = AUTOCONNECT_FLICKER_PERIODDC;
uint8_t tw = AUTOCONNECT_FLICKER_WIDTHDC;
if (WiFi.getMode() == WIFI_AP_STA) {
tc = AUTOCONNECT_FLICKER_PERIODAP;
tw = AUTOCONNECT_FLICKER_WIDTHAP;
}
_ticker->start(tc, tw);
}
}
/**

@ -2,8 +2,8 @@
* Predefined AutoConnect configuration parameters.
* @file AutoConnectDefs.h
* @author hieromon@gmail.com
* @version 1.1.5
* @date 2020-03-16
* @version 1.2.0
* @date 2020-04-23
* @copyright MIT license.
*/

Loading…
Cancel
Save