From 284b19b276067059181d01b5590f7faa642bb081 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Mon, 31 Dec 2018 02:27:48 +0900 Subject: [PATCH] Improved stability with ESP32 --- src/AutoConnect.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index ec3d17a..b734341 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -91,11 +91,14 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long _portalTimeout = timeout; // Start WiFi connection with station mode. -// WiFi.softAPdisconnect(true); WiFi.enableAP(false); WiFi.mode(WIFI_STA); delay(100); + // Set host name + if (_apConfig.hostName.length()) + SET_HOSTNAME(_apConfig.hostName.c_str()); + // Advance configuration for STA mode. #ifdef AC_DEBUG String staip_s = _apConfig.staip.toString(); @@ -113,10 +116,6 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long AC_DBG("DHCP client(%s)\n", wifi_station_dhcpc_status() == DHCP_STOPPED ? "STOPPED" : "STARTED"); #endif - // Set host name - if (_apConfig.hostName.length()) - SET_HOSTNAME(_apConfig.hostName.c_str()); - // If the portal is requested promptly skip the first WiFi.begin and // immediately start the portal. if (_apConfig.immediateStart) { @@ -173,8 +172,10 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long } } WiFi.softAP(_apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _apConfig.hidden); - while (WiFi.softAPIP() == IPAddress(0, 0, 0, 0)) + while (WiFi.softAPIP() == IPAddress(0, 0, 0, 0)) { + delay(100); yield(); + } _currentHostIP = WiFi.softAPIP(); AC_DBG("SoftAP %s/%s CH(%d) H(%d) IP:%s\n", _apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _apConfig.hidden, _currentHostIP.toString().c_str()); @@ -390,8 +391,8 @@ void AutoConnect::handleRequest() { // Handling processing requests to AutoConnect. if (_rfConnect) { // Leave from the AP currently. - if (WiFi.status() == WL_CONNECTED) - _disconnectWiFi(true); +// if (WiFi.status() == WL_CONNECTED) +// _disconnectWiFi(true); // An attempt to establish a new AP. AC_DBG("Request for %s\n", reinterpret_cast(_credential.ssid));