From 9e0512e48ba7046918037582d835037cb85a60e6 Mon Sep 17 00:00:00 2001 From: Gregg Date: Wed, 22 Nov 2023 06:15:43 -0600 Subject: [PATCH] Address WebLog size issue that limited number of entries Added logic to sequentially transmit chunks of the HTML response String whenever it grows beyond 1024 bytes. This ensures the number of WebLog entries does not create a very large HTML String that eats up all the free heap space. WebLog entries are now only limited by storage of the entries themselves. Tested successfully with 500 entries. --- src/HAP.cpp | 14 +++++++++++--- src/src.ino | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/HAP.cpp b/src/HAP.cpp index 75233ab..4660033 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -1284,6 +1284,10 @@ int HAPClient::getStatusURL(){ response+="\n"; response+="

"; + LOG2("\n>>>>>>>>>> "); + LOG2(client.remoteIP()); + LOG2(" >>>>>>>>>>\n"); + if(homeSpan.webLog.maxEntries>0){ response+="\n"; int lastIndex=homeSpan.webLog.nEntries-homeSpan.webLog.maxEntries; @@ -1305,15 +1309,19 @@ int HAPClient::getStatusURL(){ sprintf(clocktime,"Unknown"); response+="\n"; + + if(response.length()>1024){ // if response grows too big, transmit chunk and reset + LOG2(response); + client.print(response); + delay(1); // slight pause seems to be required + response.clear(); + } } response+="
EntryUp TimeLog TimeClientMessage
" + String(i+1) + "" + String(uptime) + "" + String(clocktime) + "" + homeSpan.webLog.log[index].clientIP + "" + String(homeSpan.webLog.log[index].message) + "
\n"; } response+=""; - LOG2("\n>>>>>>>>>> "); - LOG2(client.remoteIP()); - LOG2(" >>>>>>>>>>\n"); LOG2(response); LOG2("\n"); client.print(response); diff --git a/src/src.ino b/src/src.ino index bad272e..43b69e3 100644 --- a/src/src.ino +++ b/src/src.ino @@ -32,7 +32,10 @@ void setup() { Serial.begin(115200); - homeSpan.setLogLevel(2); + homeSpan.setLogLevel(2) + .enableWebLog(500,"pool.ntp.org","UTC") + .setWifiCallback(wifiEstablished) + ; homeSpan.begin(Category::Lighting,"HomeSpan Max"); @@ -51,7 +54,7 @@ void setup() { ps_new(Characteristic::On)(); ps_new(Characteristic::Brightness)(50,false); } - + } ////////////////////////////////////// @@ -61,3 +64,14 @@ void loop(){ homeSpan.poll(); } + +////////////////////////////////////// + +void wifiEstablished(){ + + for(int i=0;i<600;i++){ + WEBLOG("Here is a lot of log file text that should take up a lot of space: %d",i); + delay(30); +} + +}