Changed Accessory Limit from 41 to 150 and added Memory Warning

Low Memory Watermark is compared to DEFAULT_LOW_MEM_THRESHOLD (currently set at 80,000 bytes) after HAP initialization but before WIFI connection.  If Low Memory Watermark is below DEFAULT_LOW_MEM_THRESHOLD, a WARNING is issued.

Note: memory is based on heap with MALLOC_CAP_DEFAULT capabilities
This commit is contained in:
Gregg 2023-10-29 20:55:02 -05:00
parent c835a8620f
commit 56a2f0bece
4 changed files with 25 additions and 12 deletions

View File

@ -85,7 +85,7 @@ struct HAPClient {
static const int MAX_HTTP=8096; // max number of bytes allowed for HTTP message static const int MAX_HTTP=8096; // max number of bytes allowed for HTTP message
static const int MAX_CONTROLLERS=16; // maximum number of paired controllers (HAP requires at least 16) 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 const int MAX_ACCESSORIES=150; // maximum number of allowed Accessories (HAP limit=150)
static TLV<kTLVType,11> tlv8; // TLV8 structure (HAP Section 14.1) with space for 11 TLV records of type kTLVType (HAP Table 5-6) static TLV<kTLVType,11> tlv8; // TLV8 structure (HAP Section 14.1) with space for 11 TLV records of type kTLVType (HAP Table 5-6)
static nvs_handle hapNVS; // handle for non-volatile-storage of HAP data static nvs_handle hapNVS; // handle for non-volatile-storage of HAP data

View File

@ -179,6 +179,10 @@ void Span::pollTask() {
HAPClient::init(); // read NVS and load HAP settings HAPClient::init(); // read NVS and load HAP settings
if(heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT)<DEFAULT_LOW_MEM_THRESHOLD)
LOG0("\n**** WARNING! Low Memory Watermark of %d bytes is less than Low Threshold of %d bytes. Device *may* run out of memory.\n\n",
heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT),DEFAULT_LOW_MEM_THRESHOLD);
if(!strlen(network.wifiData.ssid)){ if(!strlen(network.wifiData.ssid)){
LOG0("*** WIFI CREDENTIALS DATA NOT FOUND. "); LOG0("*** WIFI CREDENTIALS DATA NOT FOUND. ");
if(autoStartAPEnabled){ if(autoStartAPEnabled){
@ -838,13 +842,7 @@ void Span::processSerialCommand(const char *c){
break; break;
case 'm': { case 'm': {
multi_heap_info_t heapInfo; LOG0("Free Heap=%d bytes (low=%d)\n",heap_caps_get_free_size(MALLOC_CAP_DEFAULT),heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT));
heap_caps_get_info(&heapInfo,MALLOC_CAP_INTERNAL);
LOG0("Total Heap=%d (low=%d) ",heapInfo.total_free_bytes,heapInfo.minimum_free_bytes);
heap_caps_get_info(&heapInfo,MALLOC_CAP_DEFAULT);
LOG0("DRAM-Capable=%d ",heapInfo.total_free_bytes);
heap_caps_get_info(&heapInfo,MALLOC_CAP_EXEC);
LOG0("IRAM-Capable=%d\n",heapInfo.total_free_bytes);
} }
break; break;

View File

@ -84,6 +84,8 @@
#define DEFAULT_WEBLOG_URL "status" // change with optional fourth argument in homeSpan.enableWebLog() #define DEFAULT_WEBLOG_URL "status" // change with optional fourth argument in homeSpan.enableWebLog()
#define DEFAULT_LOW_MEM_THRESHOLD 80000 // default low watermark memory threshold that triggers warning
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// OTA PARTITION INFO // // OTA PARTITION INFO //

View File

@ -74,7 +74,7 @@ void setup() {
// homeSpan.enableOTA(); // homeSpan.enableOTA();
homeSpan.setWifiCallback(wifiCB); homeSpan.setWifiCallback(wifiCB);
homeSpan.setWifiCallbackAll(wifiCB_ALL).setVerboseWifiReconnect(false); homeSpan.setWifiCallbackAll(wifiCB_ALL).setVerboseWifiReconnect(true);
new SpanUserCommand('D', " - disconnect WiFi", [](const char *buf){WiFi.disconnect();}); new SpanUserCommand('D', " - disconnect WiFi", [](const char *buf){WiFi.disconnect();});
@ -84,7 +84,20 @@ void setup() {
new SpanAccessory(); new SpanAccessory();
new Service::AccessoryInformation(); new Service::AccessoryInformation();
new Characteristic::Identify(); new Characteristic::Identify();
new LED_Service(13); // new LED_Service(13);
for(int i=0;i<50;i++){
new SpanAccessory();
new Service::AccessoryInformation();
new Characteristic::Identify();
new Service::LightBulb();
new Characteristic::On(true);
new Service::Fan();
new Characteristic::Active();
new Characteristic::RotationDirection();
(new Characteristic::RotationSpeed(50))->setRange(0,100,25);
}
} }
////////////////////////////////////// //////////////////////////////////////