From 3c3e5c21eaec6294b2f98132c3aff10c4d836d30 Mon Sep 17 00:00:00 2001 From: Gregg Date: Fri, 12 Jan 2024 21:57:57 -0600 Subject: [PATCH] Added homeSpan.getAutoPollTask() to return task handler of autoPoll Returns NULL if autoPoll has not been used. Also added low stack size for both main Arduino loop task and HomeSpan autoPoll task to 'm' command --- src/HomeSpan.cpp | 6 +++++- src/HomeSpan.h | 3 +++ src/src.ino | 7 ++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 5772f10..4fd5cf4 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -55,6 +55,8 @@ HapCharacteristics hapChars; // Instantiation of all HAP Characteristics /////////////////////////////// void Span::begin(Category catID, const char *displayName, const char *hostNameBase, const char *modelName){ + + loopTaskHandle=xTaskGetCurrentTaskHandle(); // a roundabout way of getting the current task handle this->displayName=displayName; this->hostNameBase=hostNameBase; @@ -834,7 +836,9 @@ void Span::processSerialCommand(const char *c){ Serial.printf(" Internal: %9d %9d %9d %9d\n",heapInternal.total_allocated_bytes,heapInternal.total_free_bytes,heapInternal.largest_free_block,heapInternal.minimum_free_bytes); Serial.printf(" PSRAM: %9d %9d %9d %9d\n\n",heapPSRAM.total_allocated_bytes,heapPSRAM.total_free_bytes,heapPSRAM.largest_free_block,heapPSRAM.minimum_free_bytes); - LOG0("Lowest stack level: %d bytes\n",uxTaskGetStackHighWaterMark(NULL)); + if(getAutoPollTask()) + LOG0("Lowest stack level: %d bytes (%s)\n",uxTaskGetStackHighWaterMark(getAutoPollTask()),pcTaskGetName(getAutoPollTask())); + LOG0("Lowest stack level: %d bytes (%s)\n",uxTaskGetStackHighWaterMark(loopTaskHandle),pcTaskGetName(loopTaskHandle)); nvs_stats_t nvs_stats; nvs_get_stats(NULL, &nvs_stats); LOG0("NVS Flash Partition: %d of %d records used\n\n",nvs_stats.used_entries,nvs_stats.total_entries-126); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index e90cc8d..e916b22 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -249,6 +249,7 @@ class Span{ Network network; // configures WiFi and Setup Code via either serial monitor or temporary Access Point SpanWebLog webLog; // optional web status/log TaskHandle_t pollTaskHandle = NULL; // optional task handle to use for poll() function + TaskHandle_t loopTaskHandle; // Arduino Loop Task handle boolean verboseWifiReconnect = true; // set to false to not print WiFi reconnect attempts messages SpanOTA spanOTA; // manages OTA process @@ -370,6 +371,8 @@ class Span{ LOG0("\n*** AutoPolling Task started with priority=%d\n\n",uxTaskPriorityGet(pollTaskHandle)); } + TaskHandle_t getAutoPollTask(){return(pollTaskHandle);} + Span& setTimeServerTimeout(uint32_t tSec){webLog.waitTime=tSec*1000;return(*this);} // sets wait time (in seconds) for optional web log time server to connect [[deprecated("Please use reserveSocketConnections(n) method instead.")]] diff --git a/src/src.ino b/src/src.ino index 156286a..2c98de2 100644 --- a/src/src.ino +++ b/src/src.ino @@ -29,8 +29,6 @@ #define MAX_LIGHTS 2 -SpanCharacteristic *brightness[2]; - void setup() { Serial.begin(115200); @@ -53,14 +51,13 @@ void setup() { new Characteristic::Name(c); new Service::LightBulb(); new Characteristic::On(0,true); - brightness[i]=new Characteristic::Saturation(0,true); + new Characteristic::Saturation(0,true); WEBLOG("Configuring %s\n",c); } new SpanUserCommand('w', " - get web log test",webLogTest); // simulate getting an HTTPS request for weblog - new SpanUserCommand('b', " - change brightness to fraction",[](const char *buf){brightness[0]->setVal(atof(buf+1));}); // simulate getting an HTTPS request for weblog - new SpanUserCommand('c', " - change brightness to fraction",[](const char *buf){brightness[1]->setVal(atof(buf+1));}); // simulate getting an HTTPS request for weblog +// homeSpan.autoPoll(8192+10000); } //////////////////////////////////////