Created captiveAccessURL()
Developing captive AP routines inside HAP.cpp
This commit is contained in:
parent
cd5b3115f5
commit
efe33fcdb9
60
src/HAP.cpp
60
src/HAP.cpp
|
|
@ -163,6 +163,13 @@ void HAPClient::processRequest(){
|
|||
LOG2(body);
|
||||
LOG2("\n------------ END BODY! ------------\n");
|
||||
|
||||
if(homeSpan.needsConfiguration){ // device not yet configured - only allow certain URLs
|
||||
|
||||
captiveAccessURL(); // default action for all other URLs when in captive Access Point mode
|
||||
return;
|
||||
|
||||
} // captive access point URLs only
|
||||
|
||||
if(!strncmp(body,"POST ",5)){ // this is a POST request
|
||||
|
||||
if(cLen==0){
|
||||
|
|
@ -332,6 +339,59 @@ int HAPClient::unauthorizedError(){
|
|||
|
||||
//////////////////////////////////////
|
||||
|
||||
int HAPClient::captiveAccessURL(){
|
||||
|
||||
LOG1("In Captive Access...\n");
|
||||
|
||||
int n=WiFi.scanNetworks();
|
||||
|
||||
String s="HTTP/1.1 200 OK\r\nContent-type:text/html\r\n\r\n";
|
||||
s+="<html><head><title>HomeSpan Configuration</title><style>p{font-size:300%; margin:25px}label{font-size:300%; margin:25px}input{font-size:250%; margin:25px}</style></head>";
|
||||
s+="<body style=\"background-color:lightyellow;\"><center><p><b>HomeSpan_12_54_DD_E4_23_F5</b></p></center>";
|
||||
s+="<p>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.</p>";
|
||||
s+="<p>The LED on this device should be <em>double-blinking</em> during this configuration.<p>";
|
||||
|
||||
s+="<form method=\"post\">";
|
||||
s+="<label for=\"ssid\">WiFi Network:</label>";
|
||||
s+="<input list=\"network\" name=\"network\" placeholder=\"Choose or Type\" required>";
|
||||
s+="<datalist id=\"network\">";
|
||||
|
||||
for(int i=0;i<n;i++){
|
||||
if(s.indexOf(WiFi.SSID(i))==-1) // first time this SSID founx
|
||||
s+="<option value=\"" + WiFi.SSID(i) + "\">" + WiFi.SSID(i) + "</option>";
|
||||
}
|
||||
s+="</datalist><br><br>";
|
||||
|
||||
s+="<label for=\"pwd\">WiFi Password:</label>";
|
||||
s+="<input type=\"password\" id=\"pwd\" name=\"pwd\">";
|
||||
s+="<br><br>";
|
||||
|
||||
s+="<label for=\"code\">Setup Code:</label>";
|
||||
s+="<input type=\"tel\" id=\"code\" name=\"code\" placeholder=\"12345678\" pattern=\"[0-9]{8}\">";
|
||||
|
||||
/*
|
||||
apClient.print("<p><em>");
|
||||
apClient.print("This device already has a Setup Code. You may leave Setup Code blank to retain the current one, or type a new Setup Code to change.");
|
||||
apClient.print("This device does not yet have a Setup Code. You must create one above.");
|
||||
apClient.print("</p>");
|
||||
*/
|
||||
|
||||
s+="<center><input style=\"font-size:300%\" type=\"submit\" value=\"SUBMIT\"></center>";
|
||||
s+="</form></body></html>";
|
||||
|
||||
LOG2("\n>>>>>>>>>> ");
|
||||
LOG2(client.remoteIP());
|
||||
LOG2(" >>>>>>>>>>\n");
|
||||
LOG2(s);
|
||||
LOG2("\n");
|
||||
client.print(s);
|
||||
LOG2("------------ SENT! --------------\n");
|
||||
return(1);
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
int HAPClient::postPairSetupURL(){
|
||||
|
||||
LOG1("In Pair Setup...");
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ struct HAPClient {
|
|||
// define member methods
|
||||
|
||||
void processRequest(); // process HAP request
|
||||
int captiveAccessURL(); // default process for requests made when in captive access point mode
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -353,15 +353,9 @@ void Span::configure(char *apName){
|
|||
dnsServer.start(DNS_PORT, "*", apIP);
|
||||
apServer.begin();
|
||||
|
||||
boolean configured=false;
|
||||
needsConfiguration=true;
|
||||
|
||||
TODO: Eliminate these two lines and replace with a new generic CaptiveAP flag to trackAP mode
|
||||
ALSO CHANGE HAP[0] to POINTER REFERENCES
|
||||
|
||||
hap[0].cPair=NULL; // reset pointer to verified ID
|
||||
HAPClient::pairStatus=pairState_M1; // reset starting PAIR STATE (which may be needed if Accessory failed in middle of pair-setup)
|
||||
|
||||
while(!configured){
|
||||
while(needsConfiguration){
|
||||
|
||||
dnsServer.processNextRequest();
|
||||
|
||||
|
|
@ -395,7 +389,7 @@ void Span::configure(char *apName){
|
|||
while(1);
|
||||
|
||||
|
||||
while(!configured){
|
||||
while(!needsConfiguration){
|
||||
dnsServer.processNextRequest();
|
||||
WiFiClient apClient=apServer.available();
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,9 @@ struct Span{
|
|||
unsigned long resetTime; // tracks time once reset button is pressed
|
||||
|
||||
Blinker statusLED=Blinker(LED_BUILTIN); // indicates HomeSpan status
|
||||
|
||||
|
||||
boolean needsConfiguration=false; // tracks whether device needs to be configured with WiFi credentials and a Setup Code
|
||||
|
||||
SpanConfig hapConfig; // track configuration changes to the HAP Accessory database; used to increment the configuration number (c#) when changes found
|
||||
vector<SpanAccessory *> Accessories; // vector of pointers to all Accessories
|
||||
vector<SpanService *> Loops; // vector of pointer to all Services that have over-ridden loop() methods
|
||||
|
|
|
|||
Loading…
Reference in New Issue