Added new method homeSpan.setPortNum(port)
HomeSpan defaults to running the HAP Server on port 80 (the standard HTTP port). This method allows the user to over-ride the default and have HomeSpan run the HAP Server on any other port. ALSO: In updating this portion of the code, identified an additional parameter to the ESP32 version of WiFiServer that allows one to specify the number of simultaneous Server connections. The ESP32 default is 4, which suggests that the ESP32 was internally juggling connections that HomeSpan was keeping open (since the HomeSpan default is 8 connections). This WiFiServer call has been updated to now specify both the port number AND the number of maximum simultaneous connections (to match whatever has been set by HomeSpan). This may or may not result in improving performance when more than 4 clients are connected.
This commit is contained in:
parent
b87a3d1dc3
commit
750a658241
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ void setup() {
|
|||
homeSpan.setLogLevel(2);
|
||||
|
||||
homeSpan.setHostNameSuffix("");
|
||||
homeSpan.setPortNum(1200);
|
||||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpanTest");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue