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:
parent
2bc107032c
commit
9e0512e48b
14
src/HAP.cpp
14
src/HAP.cpp
|
|
@ -1284,6 +1284,10 @@ int HAPClient::getStatusURL(){
|
||||||
response+="</table>\n";
|
response+="</table>\n";
|
||||||
response+="<p></p>";
|
response+="<p></p>";
|
||||||
|
|
||||||
|
LOG2("\n>>>>>>>>>> ");
|
||||||
|
LOG2(client.remoteIP());
|
||||||
|
LOG2(" >>>>>>>>>>\n");
|
||||||
|
|
||||||
if(homeSpan.webLog.maxEntries>0){
|
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";
|
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;
|
int lastIndex=homeSpan.webLog.nEntries-homeSpan.webLog.maxEntries;
|
||||||
|
|
@ -1305,15 +1309,19 @@ int HAPClient::getStatusURL(){
|
||||||
sprintf(clocktime,"Unknown");
|
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";
|
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+="</table>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
response+="</body></html>";
|
response+="</body></html>";
|
||||||
|
|
||||||
LOG2("\n>>>>>>>>>> ");
|
|
||||||
LOG2(client.remoteIP());
|
|
||||||
LOG2(" >>>>>>>>>>\n");
|
|
||||||
LOG2(response);
|
LOG2(response);
|
||||||
LOG2("\n");
|
LOG2("\n");
|
||||||
client.print(response);
|
client.print(response);
|
||||||
|
|
|
||||||
18
src/src.ino
18
src/src.ino
|
|
@ -32,7 +32,10 @@ void setup() {
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
homeSpan.setLogLevel(2);
|
homeSpan.setLogLevel(2)
|
||||||
|
.enableWebLog(500,"pool.ntp.org","UTC")
|
||||||
|
.setWifiCallback(wifiEstablished)
|
||||||
|
;
|
||||||
|
|
||||||
homeSpan.begin(Category::Lighting,"HomeSpan Max");
|
homeSpan.begin(Category::Lighting,"HomeSpan Max");
|
||||||
|
|
||||||
|
|
@ -51,7 +54,7 @@ void setup() {
|
||||||
ps_new(Characteristic::On)();
|
ps_new(Characteristic::On)();
|
||||||
ps_new(Characteristic::Brightness)(50,false);
|
ps_new(Characteristic::Brightness)(50,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
@ -61,3 +64,14 @@ void loop(){
|
||||||
homeSpan.poll();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue