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

added option to continue setup procedure even if Wifi is Disconnect. #91

Open
wants to merge 1 commit 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
47 changes: 28 additions & 19 deletions src/AutoConnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long

// Activate the AP mode with configured softAP and start the access point.
WiFi.mode(WIFI_AP_STA);
while (WiFi.getMode() != WIFI_AP_STA) {

while (WiFi.getMode() != WIFI_AP_STA && !_apConfig.contuineOnDisconnect) {
delay(1);
yield();
}
Expand All @@ -177,20 +178,26 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long
}
#endif
WiFi.softAP(_apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _apConfig.hidden);
do {
delay(100);
yield();
} while (WiFi.softAPIP() == IPAddress(0, 0, 0, 0));
if(!_apConfig.contuineOnDisconnect)
{
do {
delay(100);
yield();
} while (WiFi.softAPIP() == IPAddress(0, 0, 0, 0));
}
#if defined(ARDUINO_ARCH_ESP32)
if (!(_apConfig.apip == IPAddress(0, 0, 0, 0) || _apConfig.gateway == IPAddress(0, 0, 0, 0) || _apConfig.netmask == IPAddress(0, 0, 0, 0))) {
_config();
}
#endif
if (_apConfig.apip != IPAddress(0, 0, 0, 0)) {
do {
delay(100);
yield();
} while (WiFi.softAPIP() != _apConfig.apip);
if(!_apConfig.contuineOnDisconnect)
{
if (_apConfig.apip != IPAddress(0, 0, 0, 0)) {
do {
delay(100);
yield();
} while (WiFi.softAPIP() != _apConfig.apip);
}
}
_currentHostIP = WiFi.softAPIP();
AC_DBG("SoftAP %s/%s Ch(%d) IP:%s %s\n", _apConfig.apid.c_str(), _apConfig.psk.c_str(), _apConfig.channel, _currentHostIP.toString().c_str(), _apConfig.hidden ? "hidden" : "");
Expand All @@ -210,15 +217,17 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long
// Start the captive portal to make a new connection
bool hasTimeout = false;
_portalAccessPeriod = millis();
while (WiFi.status() != WL_CONNECTED && !_rfReset) {
handleClient();
// Force execution of queued processes.
yield();
// Check timeout
if ((hasTimeout = _hasTimeout(_apConfig.portalTimeout))) {
AC_DBG("CP timeout exceeded:%ld\n", millis() - _portalAccessPeriod);
break;
}
if(!_apConfig.contuineOnDisconnect)
{
while (WiFi.status() != WL_CONNECTED && !_rfReset) {
handleClient();
// Force execution of queued processes.
yield();
// Check timeout
if ((hasTimeout = _hasTimeout(_apConfig.portalTimeout))) {
AC_DBG("CP timeout exceeded:%ld\n", millis() - _portalAccessPeriod);
break;
}
}
cs = WiFi.status() == WL_CONNECTED;

Expand Down
4 changes: 4 additions & 0 deletions src/AutoConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class AutoConnectConfig {
autoReconnect(false),
immediateStart(false),
retainPortal(false),
contuineOnDisconnect(false),
portalTimeout(AUTOCONNECT_CAPTIVEPORTAL_TIMEOUT),
hostName(String("")),
homeUri(AUTOCONNECT_HOMEURI),
Expand Down Expand Up @@ -97,6 +98,7 @@ class AutoConnectConfig {
autoReconnect(false),
immediateStart(false),
retainPortal(false),
contuineOnDisconnect(false),
portalTimeout(portalTimeout),
hostName(String("")),
homeUri(AUTOCONNECT_HOMEURI),
Expand Down Expand Up @@ -126,6 +128,7 @@ class AutoConnectConfig {
autoReconnect = o.autoReconnect;
immediateStart = o.immediateStart;
retainPortal = o.retainPortal;
contuineOnDisconnect = o.contuineOnDisconnect;
portalTimeout = o.portalTimeout;
hostName = o.hostName;
homeUri = o.homeUri;
Expand Down Expand Up @@ -154,6 +157,7 @@ class AutoConnectConfig {
bool autoReconnect; /**< Automatic reconnect with past SSID */
bool immediateStart; /**< Skips WiFi.begin(), start portal immediately */
bool retainPortal; /**< Even if the captive portal times out, it maintains the portal state. */
bool contuineOnDisconnect; /**< Dont stop setup method on when WIFI is Disconnected. */
unsigned long portalTimeout; /**< Timeout value for stay in the captive portal */
String hostName; /**< host name */
String homeUri; /**< A URI of user site */
Expand Down