Added homeSpan.setWebLogCSS(const char *css)

Allows user to define a custom style sheet to change the webLog output.  Style sheet is based on pre-defined class:

bod1 = main body of web page, including header (in format of <h2>)
tabl1 = top table showing general status
tab2 = bottom table showing all weblog entries
This commit is contained in:
Gregg 2023-04-23 10:01:00 -05:00
parent 6fca946dd5
commit 947e2af012
2 changed files with 7 additions and 6 deletions

View File

@ -1246,12 +1246,10 @@ int HAPClient::getStatusURL(){
String response="HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n";
response+="<html><head><title>" + String(homeSpan.displayName) + "</title>\n";
response+="<style>th, td {padding-right: 10px; padding-left: 10px; border:1px solid black;}";
response+="</style></head>\n";
response+="<body style=\"background-color:lightblue;\">\n";
response+="<p><b>" + String(homeSpan.displayName) + "</b></p>\n";
response+="<style>body {background-color:lightblue;} th, td {padding-right: 10px; padding-left: 10px; border:1px solid black;}" + homeSpan.webLog.css + "</style></head>\n";
response+="<body class=bod1><h2>" + String(homeSpan.displayName) + "</h2>\n";
response+="<table>\n";
response+="<table class=tab1>\n";
response+="<tr><td>Up Time:</td><td>" + String(uptime) + "</td></tr>\n";
response+="<tr><td>Current Time:</td><td>" + String(clocktime) + "</td></tr>\n";
response+="<tr><td>Boot Time:</td><td>" + String(homeSpan.webLog.bootTime) + "</td></tr>\n";
@ -1276,7 +1274,7 @@ int HAPClient::getStatusURL(){
response+="<p></p>";
if(homeSpan.webLog.maxEntries>0){
response+="<table><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;
if(lastIndex<0)
lastIndex=0;

View File

@ -151,6 +151,7 @@ struct SpanWebLog{ // optional web status/log data
char bootTime[33]="Unknown"; // boot time
String statusURL; // URL of status log
uint32_t waitTime=10000; // number of milliseconds to wait for initial connection to time server
String css=""; // optional user-defined style sheet for web log
struct log_t { // log entry type
uint64_t upTime; // number of seconds since booting
@ -341,6 +342,8 @@ class Span{
va_end(ap);
}
void setWebLogCSS(const char *css){webLog.css="\n" + String(css) + "\n";}
void autoPoll(uint32_t stackSize=8192, uint32_t priority=1, uint32_t cpu=0){ // start pollTask()
xTaskCreateUniversal([](void *parms){for(;;)homeSpan.pollTask();}, "pollTask", stackSize, NULL, priority, &pollTaskHandle, cpu);
Serial.printf("\n*** AutoPolling Task started with priority=%d\n\n",uxTaskPriorityGet(pollTaskHandle));