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.
This commit is contained in:
Gregg 2023-11-22 06:15:43 -06:00
parent 2bc107032c
commit 9e0512e48b
2 changed files with 27 additions and 5 deletions

View File

@ -1284,6 +1284,10 @@ int HAPClient::getStatusURL(){
response+="</table>\n";
response+="<p></p>";
LOG2("\n>>>>>>>>>> ");
LOG2(client.remoteIP());
LOG2(" >>>>>>>>>>\n");
if(homeSpan.webLog.maxEntries>0){
response+="<table class=tab2><tr><th>Entry</th><th>Up Time</th><th>Log Time</th><th>Client</th><th>Message</th></tr>\n";
int lastIndex=homeSpan.webLog.nEntries-homeSpan.webLog.maxEntries;
@ -1305,15 +1309,19 @@ int HAPClient::getStatusURL(){
sprintf(clocktime,"Unknown");
response+="<tr><td>" + String(i+1) + "</td><td>" + String(uptime) + "</td><td>" + String(clocktime) + "</td><td>" + homeSpan.webLog.log[index].clientIP + "</td><td>" + String(homeSpan.webLog.log[index].message) + "</td></tr>\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+="</table>\n";
}
response+="</body></html>";
LOG2("\n>>>>>>>>>> ");
LOG2(client.remoteIP());
LOG2(" >>>>>>>>>>\n");
LOG2(response);
LOG2("\n");
client.print(response);

View File

@ -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");
@ -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);
}
}