Added homeSpan.setWebLogCallback(String (*f)())

Allows extension of initial table produced in WebLog, where f is a function that returns a String.  The returned String is copied into the WebLog HTML just before the </table> tag is printed in the initial table.
This commit is contained in:
Gregg 2023-10-22 18:23:25 -05:00
parent 34651307db
commit 0f96d0fff6
3 changed files with 19 additions and 3 deletions

View File

@ -1277,6 +1277,10 @@ int HAPClient::getStatusURL(){
response+="<tr><td>HomeKit Status:</td><td>" + String(HAPClient::nAdminControllers()?"PAIRED":"NOT PAIRED") + "</td></tr>\n"; response+="<tr><td>HomeKit Status:</td><td>" + String(HAPClient::nAdminControllers()?"PAIRED":"NOT PAIRED") + "</td></tr>\n";
response+="<tr><td>Max Log Entries:</td><td>" + String(homeSpan.webLog.maxEntries) + "</td></tr>\n"; response+="<tr><td>Max Log Entries:</td><td>" + String(homeSpan.webLog.maxEntries) + "</td></tr>\n";
if(homeSpan.weblogCallback)
response+=homeSpan.weblogCallback();
response+="</table>\n"; response+="</table>\n";
response+="<p></p>"; response+="<p></p>";

View File

@ -232,6 +232,7 @@ class Span{
uint16_t tcpPortNum=DEFAULT_TCP_PORT; // port for TCP communications between HomeKit and HomeSpan uint16_t tcpPortNum=DEFAULT_TCP_PORT; // port for TCP communications between HomeKit and HomeSpan
char qrID[5]=""; // Setup ID used for pairing with QR Code char qrID[5]=""; // Setup ID used for pairing with QR Code
void (*wifiCallback)()=NULL; // optional callback function to invoke once WiFi connectivity is established void (*wifiCallback)()=NULL; // optional callback function to invoke once WiFi connectivity is established
String (*weblogCallback)()=NULL; // optional callback function to invoke after header table in Web Log is produced
void (*pairCallback)(boolean isPaired)=NULL; // optional callback function to invoke when pairing is established (true) or lost (false) void (*pairCallback)(boolean isPaired)=NULL; // optional callback function to invoke when pairing is established (true) or lost (false)
boolean autoStartAPEnabled=false; // enables auto start-up of Access Point when WiFi Credentials not found boolean autoStartAPEnabled=false; // enables auto start-up of Access Point when WiFi Credentials not found
void (*apFunction)()=NULL; // optional function to invoke when starting Access Point void (*apFunction)()=NULL; // optional function to invoke when starting Access Point
@ -347,6 +348,7 @@ class Span{
} }
Span& setWebLogCSS(const char *css){webLog.css="\n" + String(css) + "\n";return(*this);} Span& setWebLogCSS(const char *css){webLog.css="\n" + String(css) + "\n";return(*this);}
Span& setWebLogCallback(String (*f)()){weblogCallback=f;return(*this);}
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);

View File

@ -39,12 +39,22 @@ struct LED_Service : Service::LightBulb {
} }
boolean update(){ boolean update(){
digitalWrite(ledPin,power->getNewVal()); digitalWrite(ledPin,power->getNewVal());
WEBLOG("Power = %s",power->getNewVal()?"ON":"OFF");
return(true); return(true);
} }
}; };
//////////////////////////////////////
String extraData(){
String r;
r+="<tr><td>Free RAM:</td><td>" + String((double)(esp_get_free_internal_heap_size() / 1024),2) + " Kb (" + String(esp_get_free_internal_heap_size()) + " bytes)</td></tr>\n";
r+="<tr><td>Free PSRAM:</td><td>" + String((double)(esp_get_free_heap_size() / 1024 / 1024),2) + " Mb (" + String(esp_get_free_heap_size()) + " bytes)</td></tr>\n";
return(r);
}
////////////////////////////////////// //////////////////////////////////////
void setup() { void setup() {
@ -55,7 +65,7 @@ void setup() {
// homeSpan.setControlPin(21); // homeSpan.setControlPin(21);
homeSpan.setLogLevel(2); homeSpan.setLogLevel(2).enableWebLog(20).setWebLogCallback(extraData);
// homeSpan.reserveSocketConnections(10); // homeSpan.reserveSocketConnections(10);
// homeSpan.setApSSID("HS_Setup"); // homeSpan.setApSSID("HS_Setup");