From 501173344908e2488b002db5f93f1298dec715d1 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 11 Feb 2024 13:43:28 -0600 Subject: [PATCH] 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. --- src/HomeSpan.cpp | 11 ++++--- src/HomeSpan.h | 2 +- src/Network.h | 2 +- src/src.ino | 81 +++++++++++++++++++++--------------------------- 4 files changed, 44 insertions(+), 52 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 7ba2970..f45dedb 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -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); } + + 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; - statusURL="GET /" + String(url) + " "; + if(url){ + statusURL="GET /" + String(url) + " "; + isEnabled=true; + } log = (log_t *)HS_CALLOC(maxEntries,sizeof(log_t)); if(timeServer) homeSpan.reserveSocketConnections(1); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index dcc79d8..7a4d7ba 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -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 diff --git a/src/Network.h b/src/Network.h index 1cb17d4..a8bacbd 100644 --- a/src/Network.h +++ b/src/Network.h @@ -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; diff --git a/src/src.ino b/src/src.ino index 7d9a9d8..bc8e539 100644 --- a/src/src.ino +++ b/src/src.ino @@ -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 Characteristic::Identify(); - 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); - - 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(); + for(int i=0;i