From 8b4329dfd6a236e59e5458c1b1610c6ab27ddbe6 Mon Sep 17 00:00:00 2001 From: Gregg Date: Wed, 21 Oct 2020 07:37:14 -0500 Subject: [PATCH] Updated apConfig() to ignore iPhone requests with "wispr" user agent This prevents re-visits to the landing-page that resets the statusLED every time. Also eliminates the need to keep track of when landing page is accessed and to perform any initial re-direction. --- src/Network.cpp | 20 ++++++-------------- src/Network.h | 3 +-- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/Network.cpp b/src/Network.cpp index ab70a59..c813ab4 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -105,7 +105,8 @@ void Network::apConfigure(){ } WiFiServer apServer(80); - + client=NULL; + TempBuffer tempBuffer(MAX_HTTP+1); uint8_t *httpBuf=tempBuffer.buf; @@ -164,6 +165,7 @@ void Network::apConfigure(){ LOG1(client.remoteIP()); LOG1("\n"); LOG2("\n"); + delay(50); // pause to allow data buffer to begin to populate } if(client && client.available()){ // if connection exists and data is available @@ -213,11 +215,6 @@ void Network::apConfigure(){ } // process Client - if(client){ - Serial.print("*** Stopping Client ***\n"); - client.stop(); - } - } // while 1 } @@ -286,7 +283,7 @@ void Network::processRequest(char *body, char *formData){ responseBody+="

Re-trying connection to:

" + String(wifiData.ssid) + "

"; responseBody+="

Timeout in " + String((alarmTimeOut-millis())/1000) + " seconds.

"; - responseBody+="
"; + responseBody+="
"; } else { homeSpan.statusLED.start(LED_AP_CONNECTED); // slow double-blink @@ -305,11 +302,11 @@ void Network::processRequest(char *body, char *formData){ } else - if(!strncmp(body,"GET /landing-page ",18)){ // GET LANDING-PAGE + if(!strstr(body,"wispr") && !strncmp(body,"GET /hotspot-detect.html ",25)){ // GET LANDING-PAGE, but only if request does NOT contain "wispr" user agent LOG1("In Landing Page...\n"); - landingPage=true; + homeSpan.statusLED.start(LED_AP_CONNECTED); responseBody+="

Welcome to HomeSpan! This page allows you to configure the above HomeSpan device to connect to your WiFi network.

" "

The LED on this device should be double-blinking during this configuration.

" @@ -331,11 +328,6 @@ void Network::processRequest(char *body, char *formData){ responseBody+="
"; - } else - - if(!landingPage){ - responseHead="HTTP/1.1 307 Temporary Redirect\r\nLocation: /landing-page\r\n"; - homeSpan.statusLED.start(LED_AP_CONNECTED); } responseHead+="\r\n"; // add blank line between reponse header and body diff --git a/src/Network.h b/src/Network.h index 5968d15..1e37e67 100644 --- a/src/Network.h +++ b/src/Network.h @@ -23,10 +23,9 @@ struct Network { char **ssidList=NULL; int numSSID; - WiFiClient client=NULL; // client used for HTTP calls + WiFiClient client; // client used for HTTP calls unsigned long timer; // length of time of trying to connect to WiFi unsigned long alarmTimeOut; // alarm time after which access point is shut down and HomeSpan is re-started - boolean landingPage=false; // check to see if captive access point landing page is accessed int apStatus; // tracks access point status (0=timed-out, -1=cancel, 1=save) struct {