Added MAX_ACCESSORIES limit=41

Program now halts if more than 41 Accessories are defined.  This allows for a bridge to have 40 Accessories.  HAP limit is 150, but there is not enough memory in ESP32 to robustly handle more (testing up to 50 LightBulb Services worked, but was sluggish).
This commit is contained in:
Gregg 2021-01-02 21:45:12 -06:00
parent 3aa5456881
commit 27b6bb7eba
2 changed files with 9 additions and 0 deletions

View File

@ -76,6 +76,7 @@ struct HAPClient {
static const int MAX_HTTP=8095; // max number of bytes in HTTP message buffer
static const int MAX_CONTROLLERS=16; // maximum number of paired controllers (HAP requires at least 16)
static const int MAX_ACCESSORIES=41; // maximum number of allowed Acessories (HAP limit=150, but not enough memory in ESP32 to run that many)
static TLV<kTLVType,10> tlv8; // TLV8 structure (HAP Section 14.1) with space for 10 TLV records of type kTLVType (HAP Table 5-6)
static nvs_handle hapNVS; // handle for non-volatile-storage of HAP data

View File

@ -1062,6 +1062,14 @@ int Span::sprintfAttributes(char **ids, int numIDs, int flags, char *cBuf){
SpanAccessory::SpanAccessory(uint32_t aid){
if(!homeSpan.Accessories.empty()){
if(homeSpan.Accessories.size()==HAPClient::MAX_ACCESSORIES){
Serial.print("\n\n*** FATAL ERROR: Can't create more than ");
Serial.print(HAPClient::MAX_ACCESSORIES);
Serial.print(" Accessories. Program Halting.\n\n");
while(1);
}
this->aid=homeSpan.Accessories.back()->aid+1;
if(!homeSpan.Accessories.back()->Services.empty())