Converted webLog.addLog() to variadic form
Also created WEBLOG() variadic macro
This commit is contained in:
parent
d9a9e6f31c
commit
2787966c48
|
|
@ -1316,7 +1316,7 @@ int HAPClient::getStatusURL(){
|
|||
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>\n";
|
||||
}
|
||||
response+="</table>\n";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1948,7 +1948,7 @@ void SpanWebLog::initTime(){
|
|||
Serial.printf("Acquiring Time from %s (%s)... ",timeServer,timeZone);
|
||||
configTzTime(timeZone,timeServer);
|
||||
struct tm timeinfo;
|
||||
if(getLocalTime(&timeinfo)){
|
||||
if(getLocalTime(&timeinfo,10000)){
|
||||
strftime(bootTime,sizeof(bootTime),"%c",&timeinfo);
|
||||
Serial.printf("%s\n\n",bootTime);
|
||||
homeSpan.reserveSocketConnections(1);
|
||||
|
|
@ -1960,7 +1960,7 @@ void SpanWebLog::initTime(){
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
void SpanWebLog::addLog(const char *m){
|
||||
void SpanWebLog::addLog(const char *fmt, ...){
|
||||
if(maxEntries==0)
|
||||
return;
|
||||
|
||||
|
|
@ -1971,7 +1971,12 @@ void SpanWebLog::addLog(const char *m){
|
|||
getLocalTime(&log[index].clockTime,10);
|
||||
else
|
||||
log[index].clockTime.tm_year=0;
|
||||
log[index].message=m;
|
||||
|
||||
free(log[index].message);
|
||||
va_list ap;
|
||||
va_start(ap,fmt);
|
||||
vasprintf(&log[index].message,fmt,ap);
|
||||
va_end(ap);
|
||||
|
||||
nEntries++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,12 +108,12 @@ struct SpanWebLog{ // optional web status/log data
|
|||
struct log_t { // log entry type
|
||||
uint64_t upTime; // number of seconds since booting
|
||||
struct tm clockTime; // clock time
|
||||
const char *message; // pointers to log entries of arbitrary size
|
||||
char *message; // pointers to log entries of arbitrary size
|
||||
} *log=NULL; // array of log entries
|
||||
|
||||
void init(uint16_t maxEntries, const char *serv, const char *tz, const char *url);
|
||||
void initTime();
|
||||
void addLog(const char *m);
|
||||
void addLog(const char *fmr, ...);
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
|
|
|
|||
|
|
@ -100,8 +100,8 @@
|
|||
|
||||
#define LOG1(x) if(homeSpan.logLevel>0)Serial.print(x)
|
||||
#define LOG2(x) if(homeSpan.logLevel>1)Serial.print(x)
|
||||
#define WEBLOG(format,...) homeSpan.webLog.addLog(format __VA_OPT__(,) __VA_ARGS__)
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Types of Accessory Categories //
|
||||
// Reference: HAP Section 13 //
|
||||
|
|
|
|||
Loading…
Reference in New Issue