Updated webLog logic to print system messages as well as user messaages
User messages only printer is logLevel>0. Also, user messages are prefixed in CLI with the word "WEBLOG: "
This commit is contained in:
parent
bb1874da96
commit
c891548ffa
|
|
@ -1262,7 +1262,7 @@ int HAPClient::getStatusURL(){
|
||||||
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>Reset Reason Code:</td><td>" + String(esp_reset_reason()) + "</td></tr>\n";
|
response+="<tr><td>Reset Reason Code:</td><td>" + String(esp_reset_reason()) + "</td></tr>\n";
|
||||||
response+="<tr><td>WiFi Disconnects:</td><td>" + String(homeSpan.connected/2) + "</td></tr>\n";
|
response+="<tr><td>WiFi Disconnects:</td><td>" + String(homeSpan.connected/2) + "</td></tr>\n";
|
||||||
response+="<tr><td>WiFi Signal:</td><td>" + String(WiFi.RSSI()) + " dDm</td></tr>\n";
|
response+="<tr><td>WiFi Signal:</td><td>" + String(WiFi.RSSI()) + " dBm</td></tr>\n";
|
||||||
response+="<tr><td>WiFi Gateway:</td><td>" + WiFi.gatewayIP().toString() + "</td></tr>\n";
|
response+="<tr><td>WiFi Gateway:</td><td>" + WiFi.gatewayIP().toString() + "</td></tr>\n";
|
||||||
response+="<tr><td>ESP32 Board:</td><td>" + String(ARDUINO_BOARD) + "</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>Arduino-ESP Version:</td><td>" + String(ARDUINO_ESP_VERSION) + "</td></tr>\n";
|
||||||
|
|
|
||||||
|
|
@ -398,7 +398,7 @@ void Span::checkConnect(){
|
||||||
if(WiFi.status()==WL_CONNECTED)
|
if(WiFi.status()==WL_CONNECTED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
WEBLOG("*** WiFi Connection Lost!"); // losing and re-establishing connection has not been tested
|
addWebLog(true,"*** WiFi Connection Lost!"); // losing and re-establishing connection has not been tested
|
||||||
connected++;
|
connected++;
|
||||||
waitTime=60000;
|
waitTime=60000;
|
||||||
alarmConnect=0;
|
alarmConnect=0;
|
||||||
|
|
@ -420,12 +420,7 @@ void Span::checkConnect(){
|
||||||
Serial.print(". You may type 'W <return>' to re-configure WiFi, or 'X <return>' to erase WiFi credentials. Will try connecting again in 60 seconds.\n\n");
|
Serial.print(". You may type 'W <return>' to re-configure WiFi, or 'X <return>' to erase WiFi credentials. Will try connecting again in 60 seconds.\n\n");
|
||||||
waitTime=60000;
|
waitTime=60000;
|
||||||
} else {
|
} else {
|
||||||
WEBLOG("Trying to connect to %s. Waiting %d sec",network.wifiData.ssid,waitTime/1000);
|
addWebLog(true,"Trying to connect to %s. Waiting %d sec...",network.wifiData.ssid,waitTime/1000);
|
||||||
Serial.print("Trying to connect to ");
|
|
||||||
Serial.print(network.wifiData.ssid);
|
|
||||||
Serial.print(". Waiting ");
|
|
||||||
Serial.print(waitTime/1000);
|
|
||||||
Serial.print(" second(s) for response...\n");
|
|
||||||
WiFi.begin(network.wifiData.ssid,network.wifiData.pwd);
|
WiFi.begin(network.wifiData.ssid,network.wifiData.pwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -434,14 +429,14 @@ void Span::checkConnect(){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!HAPClient::nAdminControllers())
|
||||||
|
statusLED.start(LED_PAIRING_NEEDED);
|
||||||
|
else
|
||||||
|
statusLED.on();
|
||||||
|
|
||||||
connected++;
|
connected++;
|
||||||
|
|
||||||
WEBLOG("WiFi Connected!");
|
addWebLog(true,"WiFi Connected! IP Address = %s\n",WiFi.localIP().toString().c_str());
|
||||||
Serial.print("Successfully connected to ");
|
|
||||||
Serial.print(network.wifiData.ssid);
|
|
||||||
Serial.print("! IP Address: ");
|
|
||||||
Serial.print(WiFi.localIP());
|
|
||||||
Serial.print("\n");
|
|
||||||
|
|
||||||
if(connected>1) // Do not initialize everything below if this is only a reconnect
|
if(connected>1) // Do not initialize everything below if this is only a reconnect
|
||||||
return;
|
return;
|
||||||
|
|
@ -565,12 +560,8 @@ void Span::checkConnect(){
|
||||||
|
|
||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
|
|
||||||
if(!HAPClient::nAdminControllers()){
|
if(!HAPClient::nAdminControllers())
|
||||||
Serial.print("DEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n");
|
Serial.print("DEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n");
|
||||||
statusLED.start(LED_PAIRING_NEEDED);
|
|
||||||
} else {
|
|
||||||
statusLED.on();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(wifiCallback)
|
if(wifiCallback)
|
||||||
wifiCallback();
|
wifiCallback();
|
||||||
|
|
@ -2052,26 +2043,33 @@ void SpanWebLog::initTime(){
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
void SpanWebLog::vLog(const char *fmt, va_list ap){
|
void SpanWebLog::vLog(boolean sysMsg, const char *fmt, va_list ap){
|
||||||
if(maxEntries==0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int index=nEntries%maxEntries;
|
char *buf;
|
||||||
|
vasprintf(&buf,fmt,ap);
|
||||||
|
|
||||||
log[index].upTime=esp_timer_get_time();
|
if(sysMsg)
|
||||||
if(timeInit)
|
Serial.printf("%s\n",buf);
|
||||||
getLocalTime(&log[index].clockTime,10);
|
else if(homeSpan.logLevel>0)
|
||||||
else
|
Serial.printf("WEBLOG: %s\n",buf);
|
||||||
log[index].clockTime.tm_year=0;
|
|
||||||
|
|
||||||
free(log[index].message);
|
if(maxEntries>0){
|
||||||
vasprintf(&log[index].message,fmt,ap);
|
int index=nEntries%maxEntries;
|
||||||
|
|
||||||
log[index].clientIP=homeSpan.lastClientIP;
|
log[index].upTime=esp_timer_get_time();
|
||||||
nEntries++;
|
if(timeInit)
|
||||||
|
getLocalTime(&log[index].clockTime,10);
|
||||||
|
else
|
||||||
|
log[index].clockTime.tm_year=0;
|
||||||
|
|
||||||
if(homeSpan.logLevel>0)
|
log[index].message=(char *)realloc(log[index].message, strlen(buf) + 1);
|
||||||
Serial.printf("WEBLOG: %s\n",log[index].message);
|
strcpy(log[index].message, buf);
|
||||||
|
|
||||||
|
log[index].clientIP=homeSpan.lastClientIP;
|
||||||
|
nEntries++;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ struct SpanWebLog{ // optional web status/log data
|
||||||
|
|
||||||
void init(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 initTime();
|
||||||
void vLog(const char *fmr, va_list ap);
|
void vLog(boolean sysMsg, const char *fmr, va_list ap);
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -286,10 +286,10 @@ class Span{
|
||||||
webLog.init(maxEntries, serv, tz, url);
|
webLog.init(maxEntries, serv, tz, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addWebLog(const char *fmt, ...){ // add Web Log entry
|
void addWebLog(boolean sysMsg, const char *fmt, ...){ // add Web Log entry
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap,fmt);
|
va_start(ap,fmt);
|
||||||
webLog.vLog(fmt,ap);
|
webLog.vLog(sysMsg,fmt,ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@
|
||||||
#define LOG1(format,...) if(homeSpan.getLogLevel()>0)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__)
|
#define LOG1(format,...) if(homeSpan.getLogLevel()>0)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__)
|
||||||
#define LOG2(format,...) if(homeSpan.getLogLevel()>1)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__)
|
#define LOG2(format,...) if(homeSpan.getLogLevel()>1)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__)
|
||||||
|
|
||||||
#define WEBLOG(format,...) homeSpan.addWebLog(format __VA_OPT__(,) __VA_ARGS__)
|
#define WEBLOG(format,...) homeSpan.addWebLog(false, format __VA_OPT__(,) __VA_ARGS__)
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
// Types of Accessory Categories //
|
// Types of Accessory Categories //
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue