diff --git a/src/Configure.cpp b/src/Configure.cpp index 0881238..1f6eee1 100644 --- a/src/Configure.cpp +++ b/src/Configure.cpp @@ -6,11 +6,10 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){ - String s; - String header; - - header+=""; - header+="

HomeSpan Setup

"; + String responseHead="HTTP/1.1 200 OK\r\nContent-type: text/html\r\n"; + + String responseBody="" + "

HomeSpan Setup

"; if(!strncmp(body,"POST /configure ",16) && // POST CONFIGURE strstr(body,"Content-Type: application/x-www-form-urlencoded")){ // check that content is from a form @@ -20,9 +19,8 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){ LOG1("In Post Configure...\n"); - s+="HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n" + header; - s+=""; - s+="

Initiating WiFi Connection...

"; + responseBody+="" + "

Initiating WiFi Connection...

"; } else @@ -30,9 +28,8 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){ LOG1("In Get WiFi Status...\n"); - s+="HTTP/1.1 200 OK\r\nContent-type: text/html\r\nRefresh: 5\r\n\r\n" + header; - s+="

Trying to Connect ("; - s+=String(millis()/1000) + "sec)...

"; + responseHead+="Refresh: 5\r\n"; + responseBody+="

Trying to Connect (" + String(millis()/1000) + "sec)...

"; } else { // LOGIN PAGE @@ -40,27 +37,24 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){ int n=WiFi.scanNetworks(); - s+="HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n" + header; - s+="

Welcome to HomeSpan! This page allows you to configure the above HomeSpan device to connect to your WiFi network, and (if needed) to create a Setup Code for pairing this device to HomeKit.

"; - s+="

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

"; - - s+="

"; - s+=""; - s+=""; - s+=""; + responseBody+="

Welcome to HomeSpan! This page allows you to configure the above HomeSpan device to connect to your WiFi network, and (if needed) to create a Setup Code for pairing this device to HomeKit.

" + "

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

" + "" + "" + "" + ""; for(int i=0;i" + WiFi.SSID(i) + ""; + if(responseBody.indexOf(WiFi.SSID(i))==-1) // first time this SSID found + responseBody+=""; } - s+="

"; - - s+=""; - s+=""; - s+="

"; - - s+=""; - s+=""; + + responseBody+="

" + "" + "" + "

" + "" + ""; /* apClient.print("

"); @@ -69,18 +63,21 @@ void Configure::processRequest(WiFiClient &client, char *body, char *formData){ apClient.print("

"); */ - s+="
"; - s+=""; - - + responseBody+="
" + ""; } + responseHead+="\r\n"; // add blank line between reponse header and body + responseBody+=""; // close out body and html tags + LOG2("\n>>>>>>>>>> "); LOG2(client.remoteIP()); LOG2(" >>>>>>>>>>\n"); - LOG2(s); + LOG2(responseHead); + LOG2(responseBody); LOG2("\n"); - client.print(s); + client.print(responseHead); + client.print(responseBody); LOG2("------------ SENT! --------------\n"); } // processRequest diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 8844f2f..c6f40f9 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -205,9 +205,6 @@ int Span::getFreeSlot(){ void Span::initWifi(){ - const int MAX_SSID=32; - const int MAX_PWD=64; - struct { char ssid[MAX_SSID+1]; char pwd[MAX_PWD+1]; diff --git a/src/Settings.h b/src/Settings.h index e224953..0b7b450 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -14,6 +14,12 @@ const char HOMESPAN_VERSION[]="1.0.0"; const int MAX_CONNECTIONS=8; +////////////////////////////////////////////////////// +// Maximum characters in WiFi SSID and Password // + +const int MAX_SSID=32; +const int MAX_PWD=64; + ///////////////////////////////////////////////////// // Verbosity -- controls message output // // 0=Minimal, 1=Informative, 2=All //