Updated Access Point WiFi connection logic

Matches new logic in HomeSpan CLI, except that wait time cycles from 2 to 10 seconds in steps of 2 seconds, then repeats, since user is expected to be manually monitoring the process, and the Access Point auto times-out in 300 seconds anyway.
This commit is contained in:
Gregg 2021-01-05 20:42:29 -06:00
parent 368c7f6d69
commit f9e317a3b1
2 changed files with 10 additions and 5 deletions

View File

@ -275,7 +275,7 @@ void Network::processRequest(char *body, char *formData){
homeSpan.statusLED.start(LED_WIFI_CONNECTING); homeSpan.statusLED.start(LED_WIFI_CONNECTING);
responseBody+="<meta http-equiv = \"refresh\" content = \"5; url = /wifi-status\" />" responseBody+="<meta http-equiv = \"refresh\" content = \"" + String(waitTime) + "; url = /wifi-status\" />"
"<p>Initiating WiFi connection to:</p><p><b>" + String(wifiData.ssid) + "</p>"; "<p>Initiating WiFi connection to:</p><p><b>" + String(wifiData.ssid) + "</p>";
WiFi.begin(wifiData.ssid,wifiData.pwd); WiFi.begin(wifiData.ssid,wifiData.pwd);
@ -308,10 +308,13 @@ void Network::processRequest(char *body, char *formData){
LOG1("In Get WiFi Status...\n"); LOG1("In Get WiFi Status...\n");
if(WiFi.status()!=WL_CONNECTED){ if(WiFi.status()!=WL_CONNECTED){
responseHead+="Refresh: 5\r\n"; waitTime+=2;
if(waitTime==12)
responseBody+="<p>Re-trying connection to:</p><p><b>" + String(wifiData.ssid) + "</p>"; waitTime=2;
responseBody+="<p>Timeout in " + String((alarmTimeOut-millis())/1000) + " seconds.</p>"; responseHead+="Refresh: " + String(waitTime) + "\r\n";
responseBody+="<p>Re-initiating connection to:</p><p><b>" + String(wifiData.ssid) + "</b></p>";
responseBody+="<p>(waiting " + String(waitTime) + " seconds to check for response)</p>";
responseBody+="<p>Access Point termination in " + String((alarmTimeOut-millis())/1000) + " seconds.</p>";
responseBody+="<center><button onclick=\"document.location='/hotspot-detect.html'\">Cancel</button></center>"; responseBody+="<center><button onclick=\"document.location='/hotspot-detect.html'\">Cancel</button></center>";
WiFi.begin(wifiData.ssid,wifiData.pwd); WiFi.begin(wifiData.ssid,wifiData.pwd);
@ -338,6 +341,7 @@ void Network::processRequest(char *body, char *formData){
LOG1("In Landing Page...\n"); LOG1("In Landing Page...\n");
homeSpan.statusLED.start(LED_AP_CONNECTED); homeSpan.statusLED.start(LED_AP_CONNECTED);
waitTime=2;
responseBody+="<p>Welcome to HomeSpan! This page allows you to configure the above HomeSpan device to connect to your WiFi network.</p>" responseBody+="<p>Welcome to HomeSpan! This page allows you to configure the above HomeSpan device to connect to your WiFi network.</p>"
"<p>The LED on this device should be <em>double-blinking</em> during this configuration.</p>" "<p>The LED on this device should be <em>double-blinking</em> during this configuration.</p>"

View File

@ -50,6 +50,7 @@ struct Network {
int numSSID; int numSSID;
WiFiClient client; // client used for HTTP calls WiFiClient client; // client used for HTTP calls
int waitTime; // time to wait between HTTP refreshed when checking for WiFi connection
unsigned long alarmTimeOut; // alarm time after which access point is shut down and HomeSpan is re-started unsigned long alarmTimeOut; // alarm time after which access point is shut down and HomeSpan is re-started
int apStatus; // tracks access point status (0=timed-out, -1=cancel, 1=save) int apStatus; // tracks access point status (0=timed-out, -1=cancel, 1=save)