From b64bd3a23020c9453e0eea921a7e05c4bb1bd712 Mon Sep 17 00:00:00 2001 From: Gregg Date: Wed, 2 Sep 2020 21:10:56 -0500 Subject: [PATCH] continued updates to captive access functionality --- src/HAP.cpp | 39 +++++++++++++++++++++++++++++++++++---- src/HAP.h | 2 ++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/HAP.cpp b/src/HAP.cpp index c82aeb7..19ee483 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -165,10 +165,21 @@ void HAPClient::processRequest(){ if(homeSpan.needsConfiguration){ // device not yet configured - only allow certain URLs + if(!strncmp(body,"POST /configure ",16) && // POST CONFIGURE + strstr(body,"Content-Type: application/x-www-form-urlencoded")){ // check that content is from a form + + content[cLen]='\0'; // add a trailing null on end of POST data + LOG2((char *)content); // print data + LOG2("\n------------ END DATA! ------------\n"); + + postConfigureURL((char *)content); // process URL + return; + } + captiveAccessURL(); // default action for all other URLs when in captive Access Point mode return; - } // captive access point URLs only + } // captive access point URLs only - everything below is for normal HAP requests if(!strncmp(body,"POST ",5)){ // this is a POST request @@ -345,13 +356,13 @@ int HAPClient::captiveAccessURL(){ int n=WiFi.scanNetworks(); - String s="HTTP/1.1 200 OK\r\nContent-type:text/html\r\n\r\n"; + String s="HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n"; s+="HomeSpan Configuration"; s+="

HomeSpan_12_54_DD_E4_23_F5

"; 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+=""; s+=""; @@ -386,8 +397,28 @@ int HAPClient::captiveAccessURL(){ LOG2("\n"); client.print(s); LOG2("------------ SENT! --------------\n"); - return(1); + return(1); +} + +////////////////////////////////////// + +int HAPClient::postConfigureURL(char *formData){ + + LOG1("In Post Configure...\n"); + + String s="HTTP/1.1 200 OK\r\nContent-type: text/html\r\nRefresh: 5\r\n\r\n"; + s+="OKAY"; + + LOG2("\n>>>>>>>>>> "); + LOG2(client.remoteIP()); + LOG2(" >>>>>>>>>>\n"); + LOG2(s); + LOG2("\n"); + client.print(s); + LOG2("------------ SENT! --------------\n"); + + return(1); } ////////////////////////////////////// diff --git a/src/HAP.h b/src/HAP.h index e94d70a..94f89e5 100644 --- a/src/HAP.h +++ b/src/HAP.h @@ -82,6 +82,8 @@ struct HAPClient { void processRequest(); // process HAP request int captiveAccessURL(); // default process for requests made when in captive access point mode + int postConfigureURL(char *formData); // POST /configure (used to process captive access mode form) + int postPairSetupURL(); // POST /pair-setup (HAP Section 5.6) int postPairVerifyURL(); // POST /pair-verify (HAP Section 5.7) int getAccessoriesURL(); // GET /accessories (HAP Section 6.6)