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:
parent
f973a92fca
commit
5011733449
|
|
@ -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)
|
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);
|
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);
|
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){
|
void SpanWebLog::init(uint16_t maxEntries, const char *serv, const char *tz, const char *url){
|
||||||
isEnabled=true;
|
|
||||||
this->maxEntries=maxEntries;
|
this->maxEntries=maxEntries;
|
||||||
timeServer=serv;
|
timeServer=serv;
|
||||||
timeZone=tz;
|
timeZone=tz;
|
||||||
statusURL="GET /" + String(url) + " ";
|
if(url){
|
||||||
|
statusURL="GET /" + String(url) + " ";
|
||||||
|
isEnabled=true;
|
||||||
|
}
|
||||||
log = (log_t *)HS_CALLOC(maxEntries,sizeof(log_t));
|
log = (log_t *)HS_CALLOC(maxEntries,sizeof(log_t));
|
||||||
if(timeServer)
|
if(timeServer)
|
||||||
homeSpan.reserveSocketConnections(1);
|
homeSpan.reserveSocketConnections(1);
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ struct SpanWebLog{ // optional web status/log data
|
||||||
boolean isEnabled=false; // flag to inidicate WebLog has been enabled
|
boolean isEnabled=false; // flag to inidicate WebLog has been enabled
|
||||||
uint16_t maxEntries=0; // max number of log entries;
|
uint16_t maxEntries=0; // max number of log entries;
|
||||||
int nEntries=0; // total cumulative 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
|
const char *timeZone; // optional time-zone specification
|
||||||
boolean timeInit=false; // flag to indicate time has been initialized
|
boolean timeInit=false; // flag to indicate time has been initialized
|
||||||
char bootTime[33]="Unknown"; // boot time
|
char bootTime[33]="Unknown"; // boot time
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ struct Network {
|
||||||
const int MAX_HTTP=4095; // max number of bytes in HTTP message
|
const int MAX_HTTP=4095; // max number of bytes in HTTP message
|
||||||
|
|
||||||
const char *apSSID=DEFAULT_AP_SSID; // Access Point SSID
|
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
|
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;
|
char **ssidList=NULL;
|
||||||
|
|
|
||||||
81
src/src.ino
81
src/src.ino
|
|
@ -1,7 +1,7 @@
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2020-2023 Gregg E. Berman
|
* Copyright (c) 2020-2024 Gregg E. Berman
|
||||||
*
|
*
|
||||||
* https://github.com/HomeSpan/HomeSpan
|
* https://github.com/HomeSpan/HomeSpan
|
||||||
*
|
*
|
||||||
|
|
@ -27,61 +27,36 @@
|
||||||
|
|
||||||
#include "HomeSpan.h"
|
#include "HomeSpan.h"
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 2
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
Serial.begin(115200);
|
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");
|
homeSpan.begin(Category::Lighting,"HomeSpan Max");
|
||||||
|
|
||||||
new SpanAccessory(); // start with Bridge Accessory
|
|
||||||
new Service::AccessoryInformation();
|
|
||||||
new Characteristic::Identify();
|
|
||||||
|
|
||||||
new SpanAccessory();
|
new SpanAccessory();
|
||||||
new Service::AccessoryInformation();
|
new Service::AccessoryInformation();
|
||||||
new Characteristic::Identify();
|
new Characteristic::Identify();
|
||||||
new Characteristic::Name("Air-1");
|
|
||||||
|
|
||||||
new Service::CarbonDioxideSensor();
|
for(int i=0;i<MAX_LIGHTS;i++){
|
||||||
new Characteristic::CarbonDioxideDetected(Characteristic::CarbonDioxideDetected::NORMAL);
|
new SpanAccessory();
|
||||||
new Characteristic::ConfiguredName("CO-1");
|
new Service::AccessoryInformation();
|
||||||
new Characteristic::StatusActive(1);
|
new Characteristic::Identify();
|
||||||
new Characteristic::StatusFault(1);
|
char c[30];
|
||||||
new Characteristic::StatusTampered(1);
|
sprintf(c,"Light-%d",i);
|
||||||
new Characteristic::StatusLowBattery(0);
|
new Characteristic::Name(c);
|
||||||
|
new Service::LightBulb();
|
||||||
new Service::AirQualitySensor();
|
new Characteristic::On(0,false);
|
||||||
new Characteristic::AirQuality(Characteristic::AirQuality::GOOD);
|
WEBLOG("Configuring %s",c);
|
||||||
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();
|
|
||||||
|
|
||||||
|
new SpanUserCommand('w', " - get web log test",webLogTest); // simulate getting an HTTPS request for weblog
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,3 +67,17 @@ void loop(){
|
||||||
homeSpan.poll();
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue