diff --git a/src/HAP.h b/src/HAP.h index b74413a..e71c6ed 100644 --- a/src/HAP.h +++ b/src/HAP.h @@ -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 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 diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 4899fa8..914c385 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -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())