Changed webLog in HomeSpan from pointer to instantiated variable
Added isEnabled to SpanWebLog to indicate whether Web Log has been enabled. This allows the use of homeSpan.webLog.addLog() without ever enabling (in which case the log entries are ignored).
This commit is contained in:
parent
acc64f863a
commit
d9a9e6f31c
24
src/HAP.cpp
24
src/HAP.cpp
|
|
@ -342,7 +342,7 @@ void HAPClient::processRequest(){
|
|||
return;
|
||||
}
|
||||
|
||||
if(homeSpan.webLog && !strncmp(body,homeSpan.webLog->statusURL.c_str(),homeSpan.webLog->statusURL.length())){ // GET STATUS - AN OPTIONAL, NON-HAP-R2 FEATURE
|
||||
if(homeSpan.webLog.isEnabled && !strncmp(body,homeSpan.webLog.statusURL.c_str(),homeSpan.webLog.statusURL.length())){ // GET STATUS - AN OPTIONAL, NON-HAP-R2 FEATURE
|
||||
getStatusURL();
|
||||
return;
|
||||
}
|
||||
|
|
@ -1258,7 +1258,7 @@ int HAPClient::getStatusURL(){
|
|||
|
||||
char clocktime[33];
|
||||
|
||||
if(homeSpan.webLog->timeInit){
|
||||
if(homeSpan.webLog.timeInit){
|
||||
struct tm timeinfo;
|
||||
getLocalTime(&timeinfo,10);
|
||||
strftime(clocktime,sizeof(clocktime),"%c",&timeinfo);
|
||||
|
|
@ -1286,37 +1286,37 @@ int HAPClient::getStatusURL(){
|
|||
response+="<table>\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>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";
|
||||
response+="<tr><td>ESP32 Board:</td><td>" + String(ARDUINO_BOARD) + "</td></tr>\n";
|
||||
response+="<tr><td>Arduino-ESP Version:</td><td>" + String(ARDUINO_ESP_VERSION) + "</td></tr>\n";
|
||||
response+="<tr><td>ESP-IDF Version:</td><td>" + String(ESP_IDF_VERSION_MAJOR) + "." + String(ESP_IDF_VERSION_MINOR) + "." + String(ESP_IDF_VERSION_PATCH) + "</td></tr>\n";
|
||||
response+="<tr><td>HomeSpan Version:</td><td>" + String(HOMESPAN_VERSION) + "</td></tr>\n";
|
||||
response+="<tr><td>Sketch Version:</td><td>" + String(homeSpan.getSketchVersion()) + "</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";
|
||||
response+="</table>\n";
|
||||
response+="<p></p>";
|
||||
|
||||
if(homeSpan.webLog->maxEntries>0){
|
||||
if(homeSpan.webLog.maxEntries>0){
|
||||
response+="<table><tr><th>Entry</th><th>Up Time</th><th>Log Time</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)
|
||||
lastIndex=0;
|
||||
|
||||
for(int i=homeSpan.webLog->nEntries-1;i>=lastIndex;i--){
|
||||
int index=i%homeSpan.webLog->maxEntries;
|
||||
seconds=homeSpan.webLog->log[index].upTime/1e6;
|
||||
for(int i=homeSpan.webLog.nEntries-1;i>=lastIndex;i--){
|
||||
int index=i%homeSpan.webLog.maxEntries;
|
||||
seconds=homeSpan.webLog.log[index].upTime/1e6;
|
||||
secs=seconds%60;
|
||||
mins=(seconds/=60)%60;
|
||||
hours=(seconds/=60)%24;
|
||||
days=(seconds/=24);
|
||||
sprintf(uptime,"%d:%02d:%02d:%02d",days,hours,mins,secs);
|
||||
|
||||
if(homeSpan.webLog->log[index].clockTime.tm_year>0)
|
||||
strftime(clocktime,sizeof(clocktime),"%c",&homeSpan.webLog->log[index].clockTime);
|
||||
if(homeSpan.webLog.log[index].clockTime.tm_year>0)
|
||||
strftime(clocktime,sizeof(clocktime),"%c",&homeSpan.webLog.log[index].clockTime);
|
||||
else
|
||||
sprintf(clocktime,"Unknown");
|
||||
|
||||
response+="<tr><td>" + String(i+1) + "</td><td>" + String(uptime) + "</td><td>" + String(clocktime) + "</td><td>" + String(homeSpan.webLog->log[index].message) + "</td/tr>";
|
||||
response+="<tr><td>" + String(i+1) + "</td><td>" + String(uptime) + "</td><td>" + String(clocktime) + "</td><td>" + String(homeSpan.webLog.log[index].message) + "</td/tr>";
|
||||
}
|
||||
response+="</table>\n";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -560,9 +560,9 @@ void Span::checkConnect(){
|
|||
}
|
||||
}
|
||||
|
||||
if(webLog){
|
||||
Serial.printf("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);
|
||||
webLog->initTime();
|
||||
if(webLog.isEnabled){
|
||||
Serial.printf("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);
|
||||
webLog.initTime();
|
||||
}
|
||||
|
||||
Serial.printf("Starting HAP Server on port %d supporting %d simultaneous HomeKit Controller Connections...\n",tcpPortNum,maxConnections);
|
||||
|
|
@ -1930,7 +1930,8 @@ SpanUserCommand::SpanUserCommand(char c, const char *s, void (*f)(const char *,
|
|||
// SpanWebLog //
|
||||
///////////////////////////////
|
||||
|
||||
SpanWebLog::SpanWebLog(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;
|
||||
timeServer=serv;
|
||||
timeZone=tz;
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ struct SpanBuf{ // temporary storage buffer for us
|
|||
///////////////////////////////
|
||||
|
||||
struct SpanWebLog{ // optional web status/log data
|
||||
boolean isEnabled=false; // flag to inidicate WebLog has been enabled
|
||||
uint16_t maxEntries; // 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
|
||||
|
|
@ -110,7 +111,7 @@ struct SpanWebLog{ // optional web status/log data
|
|||
const char *message; // pointers to log entries of arbitrary size
|
||||
} *log=NULL; // array of log entries
|
||||
|
||||
SpanWebLog(uint16_t maxEntries, const char *serv, const char *tz, const char *url);
|
||||
void init(uint16_t maxEntries, const char *serv, const char *tz, const char *url);
|
||||
void initTime();
|
||||
void addLog(const char *m);
|
||||
};
|
||||
|
|
@ -163,7 +164,7 @@ struct Span{
|
|||
Blinker statusLED; // indicates HomeSpan status
|
||||
PushButton controlButton; // controls HomeSpan configuration and resets
|
||||
Network network; // configures WiFi and Setup Code via either serial monitor or temporary Access Point
|
||||
SpanWebLog *webLog=NULL; // optional web status/log
|
||||
SpanWebLog webLog; // optional web status/log
|
||||
|
||||
SpanConfig hapConfig; // track configuration changes to the HAP Accessory database; used to increment the configuration number (c#) when changes found
|
||||
vector<SpanAccessory *> Accessories; // vector of pointers to all Accessories
|
||||
|
|
@ -225,7 +226,7 @@ struct Span{
|
|||
void enableOTA(boolean auth=true){otaEnabled=true;otaAuth=auth;reserveSocketConnections(1);} // enables Over-the-Air updates, with (auth=true) or without (auth=false) authorization password
|
||||
|
||||
void enableWebLog(uint16_t maxEntries=0, const char *serv=NULL, const char *tz="UTC", const char *url=DEFAULT_WEBLOG_URL){ // enable Web Logging
|
||||
webLog=new SpanWebLog(maxEntries, serv, tz, url);
|
||||
webLog.init(maxEntries, serv, tz, url);
|
||||
}
|
||||
|
||||
[[deprecated("Please use reserveSocketConnections(n) method instead.")]]
|
||||
|
|
|
|||
Loading…
Reference in New Issue