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 committed by Francois
parent a2bf3a8e66
commit e35808f582
2 changed files with 8 additions and 7 deletions

View File

@ -1250,11 +1250,10 @@ int HAPClient::getStatusURL(){
String response="HTTP/1.1 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n"; String response="HTTP/1.1 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n";
response+="<html><head><title>" + String(homeSpan.displayName) + "</title>\n"; response+="<html><head><title>" + String(homeSpan.displayName) + "</title>\n";
response+= String(homeSpan.webLog.cssStyle); 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+="</head>\n"; response+="<body class=bod1><h2>" + String(homeSpan.displayName) + "</h2>\n";
response+="<body>\n";
response+="<p><b>" + String(homeSpan.displayName) + "</b></p>\n"; response+="<table class=tab1>\n";
response+="<table id=homespan_hap_properties>\n";
response+="<tr><td>Up Time:</td><td>" + String(uptime) + "</td></tr>\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>Current Time:</td><td>" + String(clocktime) + "</td></tr>\n";
response+="<tr><td>Boot Time:</td><td>" + String(homeSpan.webLog.bootTime) + "</td></tr>\n"; response+="<tr><td>Boot Time:</td><td>" + String(homeSpan.webLog.bootTime) + "</td></tr>\n";
@ -1281,7 +1280,7 @@ int HAPClient::getStatusURL(){
response+="<p></p>"; response+="<p></p>";
if(homeSpan.webLog.maxEntries>0){ if(homeSpan.webLog.maxEntries>0){
response+="<table id=homespan_weblogs><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;
if(lastIndex<0) if(lastIndex<0)
lastIndex=0; lastIndex=0;

View File

@ -151,7 +151,7 @@ struct SpanWebLog{ // optional web status/log data
char bootTime[33]="Unknown"; // boot time char bootTime[33]="Unknown"; // boot time
String statusURL; // URL of status log String statusURL; // URL of status log
uint32_t waitTime=10000; // number of milliseconds to wait for initial connection to time server uint32_t waitTime=10000; // number of milliseconds to wait for initial connection to time server
String cssStyle; // Default CSS style. String css=""; // optional user-defined style sheet for web log
struct log_t { // log entry type struct log_t { // log entry type
uint64_t upTime; // number of seconds since booting uint64_t upTime; // number of seconds since booting
@ -342,6 +342,8 @@ class Span{
va_end(ap); 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() 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); 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)); Serial.printf("\n*** AutoPolling Task started with priority=%d\n\n",uxTaskPriorityGet(pollTaskHandle));