Deprecated setMaxConnections(); Added reserveSocketConnections()
Use homeSpan.reserveSocketConnections(n) to reserve n sockets *not* to be used for HAP. Multiple calls can be used to cumulate a total number of reserved sockets. This makes is easy to add reserveSocketConnections(n) at multiple point in the code whenever a certain number of sockets need to be reserved for use with that portion of the code. For example enableOTA() calls reserveSocketConnections(1). If both setMaxConnections(), and one or more reserveSocketConnections(), methods are called HomeSpan will use the more restrictive net value.
This commit is contained in:
parent
4973d1aaa1
commit
ac88329d34
|
|
@ -60,10 +60,9 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
||||||
controlButton.init(controlPin);
|
controlButton.init(controlPin);
|
||||||
statusLED.init(statusPin,0,autoOffLED);
|
statusLED.init(statusPin,0,autoOffLED);
|
||||||
|
|
||||||
int maxLimit=CONFIG_LWIP_MAX_SOCKETS-2-otaEnabled;
|
if(requestedMaxCon<maxConnections) // if specific request for max connections is less than computed max connections
|
||||||
if(maxConnections>maxLimit)
|
maxConnections=requestedMaxCon; // over-ride max connections with requested value
|
||||||
maxConnections=maxLimit;
|
|
||||||
|
|
||||||
hap=(HAPClient **)calloc(maxConnections,sizeof(HAPClient *));
|
hap=(HAPClient **)calloc(maxConnections,sizeof(HAPClient *));
|
||||||
for(int i=0;i<maxConnections;i++)
|
for(int i=0;i<maxConnections;i++)
|
||||||
hap[i]=new HAPClient;
|
hap[i]=new HAPClient;
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,8 @@ struct Span{
|
||||||
uint16_t autoOffLED=0; // automatic turn-off duration (in seconds) for Status LED
|
uint16_t autoOffLED=0; // automatic turn-off duration (in seconds) for Status LED
|
||||||
int controlPin=DEFAULT_CONTROL_PIN; // pin for Control Pushbutton
|
int controlPin=DEFAULT_CONTROL_PIN; // pin for Control Pushbutton
|
||||||
uint8_t logLevel=DEFAULT_LOG_LEVEL; // level for writing out log messages to serial monitor
|
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
|
uint8_t maxConnections=CONFIG_LWIP_MAX_SOCKETS-2; // maximum number of allowed simultaneous HAP connections
|
||||||
|
uint8_t requestedMaxCon=CONFIG_LWIP_MAX_SOCKETS-2; // requested maximum 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
|
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
|
uint16_t tcpPortNum=DEFAULT_TCP_PORT; // port for TCP communications between HomeKit and HomeSpan
|
||||||
char qrID[5]=""; // Setup ID used for pairing with QR Code
|
char qrID[5]=""; // Setup ID used for pairing with QR Code
|
||||||
|
|
@ -182,22 +183,27 @@ struct Span{
|
||||||
void setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;} // sets Access Point Timeout (seconds)
|
void setApTimeout(uint16_t nSec){network.lifetime=nSec*1000;} // sets Access Point Timeout (seconds)
|
||||||
void setCommandTimeout(uint16_t nSec){comModeLife=nSec*1000;} // sets Command Mode Timeout (seconds)
|
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 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 reserveSocketConnections(uint8_t n){maxConnections-=n;} // reserves n socket connections *not* to be used for HAP
|
||||||
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
|
void setPortNum(uint16_t port){tcpPortNum=port;} // sets the TCP port number to use for communications between HomeKit and HomeSpan
|
||||||
void setQRID(const char *id); // sets the Setup ID for optional pairing with a QR Code
|
void setQRID(const char *id); // sets the Setup ID for optional pairing with a QR Code
|
||||||
void enableOTA(boolean auth=true){otaEnabled=true;otaAuth=auth;} // enables Over-the-Air updates, with (auth=true) or without (auth=false) authorization password
|
|
||||||
void setSketchVersion(const char *sVer){sketchVersion=sVer;} // set optional sketch version number
|
void setSketchVersion(const char *sVer){sketchVersion=sVer;} // set optional sketch version number
|
||||||
const char *getSketchVersion(){return sketchVersion;} // get sketch version number
|
const char *getSketchVersion(){return sketchVersion;} // get sketch version number
|
||||||
void setWifiCallback(void (*f)()){wifiCallback=f;} // sets an optional user-defined function to call once WiFi connectivity is established
|
void setWifiCallback(void (*f)()){wifiCallback=f;} // sets an optional user-defined function to call once WiFi connectivity is established
|
||||||
void setPairCallback(void (*f)(boolean isPaired)){pairCallback=f;} // sets an optional user-defined function to call when Pairing is established (true) or lost (false)
|
void setPairCallback(void (*f)(boolean isPaired)){pairCallback=f;} // sets an optional user-defined function to call when Pairing is established (true) or lost (false)
|
||||||
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
|
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
|
||||||
|
|
||||||
void setPairingCode(const char *s){sprintf(pairingCodeCommand,"S %9s",s);} // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
|
||||||
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS
|
|
||||||
|
|
||||||
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
|
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
|
||||||
void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
||||||
|
|
||||||
|
void setPairingCode(const char *s){sprintf(pairingCodeCommand,"S %9s",s);} // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
||||||
|
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS
|
||||||
|
|
||||||
|
void enableOTA(boolean auth=true){otaEnabled=true;otaAuth=auth;reserveSocketConnections(1);} // enables Over-the-Air updates, with (auth=true) or without (auth=false) authorization password
|
||||||
|
|
||||||
|
[[deprecated("Please use reserveSocketConnections(n) method instead.")]]
|
||||||
|
void setMaxConnections(uint8_t n){requestedMaxCon=n;} // sets maximum number of simultaneous HAP connections
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,6 @@
|
||||||
|
|
||||||
#define DEFAULT_LOG_LEVEL 0 // change with homeSpan.setLogLevel(level)
|
#define DEFAULT_LOG_LEVEL 0 // change with homeSpan.setLogLevel(level)
|
||||||
|
|
||||||
#define DEFAULT_MAX_CONNECTIONS 14 // change with homeSpan.setMaxConnections(num);
|
|
||||||
#define DEFAULT_TCP_PORT 80 // change with homeSpan.setPort(port);
|
#define DEFAULT_TCP_PORT 80 // change with homeSpan.setPort(port);
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue