Added option to specify NULL for 4th parameter of homeSpan.enableWebLog()

If 4th parameter (the statusURL) is NULL, web logging will NOT be enabled BUT time server will still acquire time if server address and time zone were specified as 2nd and 3rd parameters.

Note that not having web logging enabled only impacts ability to acquire weblog from HTTP request.  It has no effect on the actual logging of WEBLOG() messages and thus homeSpan.getWebLog() works as expected.
This commit is contained in:
Gregg 2024-02-11 13:43:28 -06:00
parent f973a92fca
commit 5011733449
4 changed files with 44 additions and 52 deletions

View File

@ -535,9 +535,10 @@ void Span::checkConnect(){
mdns_service_txt_item_set("_hap","_tcp","logURL",webLog.statusURL.c_str()+4); // Web Log status (info only - NOT used by HAP)
LOG0("Web Logging enabled at http://%s.local:%d%swith max number of entries=%d\n\n",hostName,tcpPortNum,webLog.statusURL.c_str()+4,webLog.maxEntries);
}
if(webLog.timeServer)
xTaskCreateUniversal(webLog.initTime, "timeSeverTaskHandle", 8096, &webLog, 1, NULL, 0);
}
LOG0("Starting HAP Server on port %d supporting %d simultaneous HomeKit Controller Connections...\n\n",tcpPortNum,maxConnections);
@ -2098,11 +2099,13 @@ SpanUserCommand::SpanUserCommand(char c, const char *s, void (*f)(const char *,
///////////////////////////////
void SpanWebLog::init(uint16_t maxEntries, const char *serv, const char *tz, const char *url){
isEnabled=true;
this->maxEntries=maxEntries;
timeServer=serv;
timeZone=tz;
if(url){
statusURL="GET /" + String(url) + " ";
isEnabled=true;
}
log = (log_t *)HS_CALLOC(maxEntries,sizeof(log_t));
if(timeServer)
homeSpan.reserveSocketConnections(1);

View File

@ -148,7 +148,7 @@ struct SpanWebLog{ // optional web status/log data
boolean isEnabled=false; // flag to inidicate WebLog has been enabled
uint16_t maxEntries=0; // max number of log entries;
int nEntries=0; // total cumulative number of log entries
const char *timeServer; // optional time server to use for acquiring clock time
const char *timeServer=NULL; // optional time server to use for acquiring clock time
const char *timeZone; // optional time-zone specification
boolean timeInit=false; // flag to indicate time has been initialized
char bootTime[33]="Unknown"; // boot time

View File

@ -40,7 +40,7 @@ struct Network {
const int MAX_HTTP=4095; // max number of bytes in HTTP message
const char *apSSID=DEFAULT_AP_SSID; // Access Point SSID
const char *apPassword=DEFAULT_AP_PASSWORD; // Access Point password (does not need to be secret - only used to ensure excrypted WiFi connection)
const char *apPassword=DEFAULT_AP_PASSWORD; // Access Point password (does not need to be secret - only used to ensure encrypted WiFi connection)
unsigned long lifetime=DEFAULT_AP_TIMEOUT*1000; // length of time (in milliseconds) to keep Access Point alive before shutting down and restarting
char **ssidList=NULL;

View File

@ -1,7 +1,7 @@
/*********************************************************************************
* MIT License
*
* Copyright (c) 2020-2023 Gregg E. Berman
* Copyright (c) 2020-2024 Gregg E. Berman
*
* https://github.com/HomeSpan/HomeSpan
*
@ -27,61 +27,36 @@
#include "HomeSpan.h"
#define MAX_LIGHTS 2
void setup() {
Serial.begin(115200);
homeSpan.setLogLevel(2);
homeSpan.setLogLevel(1);
// homeSpan.enableWebLog(50,"pool.ntp.org","UTC",NULL);
// homeSpan.enableWebLog(50,"pool.ntp.org","UTC","myStatus");
// homeSpan.enableWebLog(50,NULL,NULL,NULL);
homeSpan.begin(Category::Sensors,"HomeSpan Sensors");
new SpanAccessory(); // start with Bridge Accessory
new Service::AccessoryInformation();
new Characteristic::Identify();
homeSpan.begin(Category::Lighting,"HomeSpan Max");
new SpanAccessory();
new Service::AccessoryInformation();
new Characteristic::Identify();
new Characteristic::Name("Air-1");
new Service::CarbonDioxideSensor();
new Characteristic::CarbonDioxideDetected(Characteristic::CarbonDioxideDetected::NORMAL);
new Characteristic::ConfiguredName("CO-1");
new Characteristic::StatusActive(1);
new Characteristic::StatusFault(1);
new Characteristic::StatusTampered(1);
new Characteristic::StatusLowBattery(0);
new Service::AirQualitySensor();
new Characteristic::AirQuality(Characteristic::AirQuality::GOOD);
new Characteristic::ConfiguredName("AQ-1");
new Characteristic::StatusActive(1);
new Characteristic::StatusFault(0);
new Characteristic::StatusTampered(0);
new Characteristic::StatusLowBattery(0);
for(int i=0;i<MAX_LIGHTS;i++){
new SpanAccessory();
new Service::AccessoryInformation();
new Characteristic::Identify();
new Characteristic::Name("Air-2");
new Service::AirQualitySensor();
new Characteristic::AirQuality(Characteristic::AirQuality::EXCELLENT);
new Characteristic::StatusActive(0);
new Characteristic::StatusFault(1);
new Characteristic::StatusTampered(1);
new Characteristic::StatusLowBattery(1);
new SpanAccessory();
new Service::AccessoryInformation();
new Characteristic::Identify();
new Characteristic::Name("Furnace Filter");
new Service::FilterMaintenance();
new Characteristic::FilterChangeIndication(Characteristic::FilterChangeIndication::CHANGE_NEEDED);
new Characteristic::FilterLifeLevel(5);
// new Characteristic::ResetFilterIndication();
char c[30];
sprintf(c,"Light-%d",i);
new Characteristic::Name(c);
new Service::LightBulb();
new Characteristic::On(0,false);
WEBLOG("Configuring %s",c);
}
new SpanUserCommand('w', " - get web log test",webLogTest); // simulate getting an HTTPS request for weblog
}
@ -92,3 +67,17 @@ void loop(){
homeSpan.poll();
}
//////////////////////////////////////
void webLogTest(const char *dummy){
Serial.printf("\n*** In Web Log Test. Starting Custom Web Log Handler\n"); // here is where you would perform any HTTPS initializations
homeSpan.getWebLog(webLogHandler); // this starts the normal weblog with output redirected to the specified handler (below)
}
void webLogHandler(const char *buf){
if(buf!=NULL)
Serial.printf("%s",buf); // here is where you would transmit data to the HTTPS connection
else
Serial.print("*** DONE!\n\n"); // here is where you would close the HTTPS connection
}