diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 2cf9e1c..3ce1a08 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -35,8 +35,6 @@ using namespace Utils; -WiFiServer hapServer(80); // HTTP Server (i.e. this acccesory) running on usual port 80 (local-scoped variable to this file only) - HAPClient **hap; // HAP Client structure containing HTTP client connections, parsing routines, and state variables (global-scoped variable) Span homeSpan; // HAP Attributes database and all related control functions for this Accessory (global-scoped variable) @@ -127,6 +125,7 @@ void Span::poll() { statusLED.start(LED_WIFI_NEEDED); } else { homeSpan.statusLED.start(LED_WIFI_CONNECTING); + hapServer=new WiFiServer(tcpPortNum,maxConnections); } controlButton.reset(); @@ -150,7 +149,7 @@ void Span::poll() { WiFiClient newClient; - if(newClient=hapServer.available()){ // found a new HTTP client + if(newClient=hapServer->available()){ // found a new HTTP client int freeSlot=getFreeSlot(); // get next free slot if(freeSlot==-1){ // no available free slots @@ -377,18 +376,20 @@ void Span::checkConnect(){ else sprintf(hostName,"%s%s",hostNameBase,hostNameSuffix); - Serial.print("\nStarting MDNS...\n"); - Serial.print("Broadcasting as: "); + Serial.print("\nStarting MDNS...\n\n"); + Serial.print("HostName: "); Serial.print(hostName); - Serial.print(".local ("); + Serial.print(".local:"); + Serial.print(tcpPortNum); + Serial.print("\nDisplay Name: "); Serial.print(displayName); - Serial.print(" / "); + Serial.print("\nModel Name: "); Serial.print(modelName); - Serial.print(")\n"); + Serial.print("\n"); - MDNS.begin(hostName); // set server host name (.local implied) - MDNS.setInstanceName(displayName); // set server display name - MDNS.addService("_hap","_tcp",80); // advertise HAP service on HTTP port (80) + MDNS.begin(hostName); // set server host name (.local implied) + MDNS.setInstanceName(displayName); // set server display name + MDNS.addService("_hap","_tcp",tcpPortNum); // advertise HAP service on specified port // add MDNS (Bonjour) TXT records for configurable as well as fixed values (HAP Table 6-7) @@ -412,7 +413,7 @@ void Span::checkConnect(){ Serial.print("\nStarting Web (HTTP) Server supporting up to "); Serial.print(maxConnections); Serial.print(" simultaneous connections...\n\n"); - hapServer.begin(); + hapServer->begin(); if(!HAPClient::nAdminControllers()){ Serial.print("DEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n"); @@ -560,7 +561,7 @@ void Span::processSerialCommand(const char *c){ if(strlen(network.wifiData.ssid)>0){ Serial.print("*** Stopping all current WiFi services...\n\n"); - hapServer.end(); + hapServer->end(); MDNS.end(); WiFi.disconnect(); } diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 09c0d49..35c1687 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -96,7 +96,9 @@ struct Span{ uint8_t logLevel=DEFAULT_LOG_LEVEL; // level for writing out log messages to serial monitor uint8_t maxConnections=DEFAULT_MAX_CONNECTIONS; // number of simultaneous HAP connections unsigned long comModeLife=DEFAULT_COMMAND_TIMEOUT*1000; // length of time (in milliseconds) to keep Command Mode alive before resuming normal operations + uint16_t tcpPortNum=DEFAULT_TCP_PORT; // port for TCP communications between HomeKit and HomeSpan + WiFiServer *hapServer; // pointer to the HAP Server connection Blinker statusLED; // indicates HomeSpan status PushButton controlButton; // controls HomeSpan configuration and resets Network network; // configures WiFi and Setup Code via either serial monitor or temporary Access Point @@ -142,7 +144,8 @@ struct Span{ void setCommandTimeout(uint16_t nSec){comModeLife=nSec*1000;} // sets Command Mode Timeout (seconds) void setLogLevel(uint8_t level){logLevel=level;} // sets Log Level for log messages (0=baseline, 1=intermediate, 2=all) void setMaxConnections(uint8_t nCon){maxConnections=nCon;} // sets maximum number of simultaneous HAP connections (HAP requires devices support at least 8) - void setHostNameSuffix(const char *suffix){hostNameSuffix=suffix;} // sets the hostName suffix to be used instead of the 6-byte AccessoryID + void setHostNameSuffix(const char *suffix){hostNameSuffix=suffix;} // sets the hostName suffix to be used instead of the 6-byte AccessoryID + void setPortNum(uint16_t port){tcpPortNum=port;} // sets the TCP port number to use for communications between HomeKit and HomeSpan }; /////////////////////////////// diff --git a/src/SRP.cpp b/src/SRP.cpp index 3112b53..8565cd0 100644 --- a/src/SRP.cpp +++ b/src/SRP.cpp @@ -225,7 +225,6 @@ int SRP6A::verifyProof(){ void SRP6A::createProof(){ uint8_t tBuf[512]; // temporary buffer for staging - uint8_t tHash[64]; // temporary buffer for storing SHA-512 results // compute M2 = H( A | M1 | K ) diff --git a/src/Settings.h b/src/Settings.h index a4dfce4..9b2a88b 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -73,6 +73,7 @@ #define DEFAULT_LOG_LEVEL 0 // change with homeSpan.setLogLevel(level) #define DEFAULT_MAX_CONNECTIONS 8 // change with homeSpan.setMaxConnections(num); +#define DEFAULT_TCP_PORT 80 // change with homeSpan.setPort(port); ///////////////////////////////////////////////////// diff --git a/src/src.ino b/src/src.ino index 87725b6..519b1cb 100644 --- a/src/src.ino +++ b/src/src.ino @@ -11,6 +11,7 @@ void setup() { homeSpan.setLogLevel(2); homeSpan.setHostNameSuffix(""); + homeSpan.setPortNum(1200); homeSpan.begin(Category::Lighting,"HomeSpanTest");