diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 9ed800d..6b347c9 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -217,11 +217,11 @@ void Span::initWifi(){ memcpy(id,HAPClient::accessory.ID,17); // copy ID bytes id[17]='\0'; // add terminating null - // create broadcaset name from server base name plus accessory ID (with ':' replaced by '_') + // create broadcaset name from server base name plus accessory ID (without ':') - int nChars=snprintf(NULL,0,"%s-%.2s_%.2s_%.2s_%.2s_%.2s_%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15); + int nChars=snprintf(NULL,0,"%s-%.2s%.2s%.2s%.2s%.2s%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15); char hostName[nChars+1]; - sprintf(hostName,"%s-%.2s_%.2s_%.2s_%.2s_%.2s_%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15); + sprintf(hostName,"%s-%.2s%.2s%.2s%.2s%.2s%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15); nvs_handle wifiHandle; size_t len; // not used but required to read blobs from NVS @@ -349,17 +349,52 @@ void Span::configure(char *apName){ IPAddress apIP(192, 168, 4, 1); WiFi.mode(WIFI_AP); - WiFi.softAP(apName,"homespan2020"); + WiFi.softAP(apName,"homespan"); dnsServer.start(DNS_PORT, "*", apIP); apServer.begin(); - String responseHTML = "" - "CaptivePortal" - "

Hello World!

This is a captive portal example. All requests will " - "be redirected here.

"; - boolean configured=false; + 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){ + + dnsServer.processNextRequest(); + + if(hap[0].client=apServer.available()){ // found a new HTTP client + LOG2("=======================================\n"); + LOG1("** Access Point Client Connected: ("); + LOG1(millis()/1000); + LOG1(" sec) "); + LOG1(hap[0].client.remoteIP()); + LOG1("\n"); + LOG2("\n"); + } + + if(hap[0].client && hap[0].client.available()){ // if connection exists and data is available + + HAPClient::conNum=0; // set connection number + hap[0].processRequest(); // process HAP request + + if(!hap[0].client){ // client disconnected by server + LOG1("** Disconnecting AP Client ("); + LOG1(millis()/1000); + LOG1(" sec)\n"); + } + + LOG2("\n"); + + } // process HAP Client + + } + + while(1); + + while(!configured){ dnsServer.processNextRequest(); WiFiClient apClient=apServer.available(); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 005f662..16ae87a 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -64,7 +64,7 @@ struct Span{ void begin(Category catID, char *displayName="HomeSpan Server", - char *hostNameBase="homespan", + char *hostNameBase="HomeSpan", char *modelName="HS-ESP32"); void poll(); // poll HAP Clients and process any new HAP requests diff --git a/src/Settings.h b/src/Settings.h index 98550b1..e224953 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -18,7 +18,7 @@ const int MAX_CONNECTIONS=8; // Verbosity -- controls message output // // 0=Minimal, 1=Informative, 2=All // -#define VERBOSITY 1 +#define VERBOSITY 2 //-------------------------------------------------// diff --git a/src/src.ino b/src/src.ino index 3ac41a3..79ceba5 100644 --- a/src/src.ino +++ b/src/src.ino @@ -1,6 +1,39 @@ -// This is a dummy .ino file that allows you to easily edit the contents of this library using the Arduino IDE. -// The code is NOT designed to be compiled from this point. Compile and test the library using one of the examples. +// This is a placeholder .ino file that allows you to easily edit the contents of this library using the Arduino IDE, +// as well as compile and test from this point. This file is ignored when the library is included in other sketchges. -void setup(){} -void loop(){} +#include "HomeSpan.h" + +void setup() { + + Serial.begin(115200); + + homeSpan.begin(Category::Lighting,"HomeSpan Benchmark"); + + char *version=(char *)HOMESPAN_VERSION; + + new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments + + new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, which has 6 required Characteristics + new Characteristic::Name("HomeSpan Test"); // Name of the Accessory, which shows up on the HomeKit "tiles", and should be unique across Accessories + new Characteristic::Manufacturer("HomeSpan"); // Manufacturer of the Accessory (arbitrary text string, and can be the same for every Accessory) + new Characteristic::SerialNumber("HSL-123"); // Serial Number of the Accessory (arbitrary text string, and can be the same for every Accessory) + new Characteristic::Model("HSL Test"); // Model of the Accessory (arbitrary text string, and can be the same for every Accessory) + new Characteristic::FirmwareRevision(version); // Firmware of the Accessory (arbitrary text string, and can be the same for every Accessory) + new Characteristic::Identify(); // Create the required Identify + + new Service::HAPProtocolInformation(); // Create the HAP Protcol Information Service + new Characteristic::Version("1.1.0"); // Set the Version Characteristicto "1.1.0" as required by HAP + + new Service::LightBulb(); // Create the Light Bulb Service + new Characteristic::On(); // This Service requires the "On" Characterstic to turn the light on and off + +} // end of setup() + +////////////////////////////////////// + +void loop(){ + + homeSpan.poll(); + +} // end of loop()