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>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 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>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";
|
||||
|
|
|
|||
|
|
@ -398,7 +398,7 @@ void Span::checkConnect(){
|
|||
if(WiFi.status()==WL_CONNECTED)
|
||||
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++;
|
||||
waitTime=60000;
|
||||
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");
|
||||
waitTime=60000;
|
||||
} else {
|
||||
WEBLOG("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");
|
||||
addWebLog(true,"Trying to connect to %s. Waiting %d sec...",network.wifiData.ssid,waitTime/1000);
|
||||
WiFi.begin(network.wifiData.ssid,network.wifiData.pwd);
|
||||
}
|
||||
|
||||
|
|
@ -434,14 +429,14 @@ void Span::checkConnect(){
|
|||
return;
|
||||
}
|
||||
|
||||
if(!HAPClient::nAdminControllers())
|
||||
statusLED.start(LED_PAIRING_NEEDED);
|
||||
else
|
||||
statusLED.on();
|
||||
|
||||
connected++;
|
||||
|
||||
WEBLOG("WiFi Connected!");
|
||||
Serial.print("Successfully connected to ");
|
||||
Serial.print(network.wifiData.ssid);
|
||||
Serial.print("! IP Address: ");
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.print("\n");
|
||||
addWebLog(true,"WiFi Connected! IP Address = %s\n",WiFi.localIP().toString().c_str());
|
||||
|
||||
if(connected>1) // Do not initialize everything below if this is only a reconnect
|
||||
return;
|
||||
|
|
@ -565,12 +560,8 @@ void Span::checkConnect(){
|
|||
|
||||
Serial.print("\n");
|
||||
|
||||
if(!HAPClient::nAdminControllers()){
|
||||
if(!HAPClient::nAdminControllers())
|
||||
Serial.print("DEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n");
|
||||
statusLED.start(LED_PAIRING_NEEDED);
|
||||
} else {
|
||||
statusLED.on();
|
||||
}
|
||||
|
||||
if(wifiCallback)
|
||||
wifiCallback();
|
||||
|
|
@ -2052,26 +2043,33 @@ void SpanWebLog::initTime(){
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
void SpanWebLog::vLog(const char *fmt, va_list ap){
|
||||
if(maxEntries==0)
|
||||
return;
|
||||
void SpanWebLog::vLog(boolean sysMsg, const char *fmt, va_list ap){
|
||||
|
||||
int index=nEntries%maxEntries;
|
||||
char *buf;
|
||||
vasprintf(&buf,fmt,ap);
|
||||
|
||||
log[index].upTime=esp_timer_get_time();
|
||||
if(timeInit)
|
||||
getLocalTime(&log[index].clockTime,10);
|
||||
else
|
||||
log[index].clockTime.tm_year=0;
|
||||
if(sysMsg)
|
||||
Serial.printf("%s\n",buf);
|
||||
else if(homeSpan.logLevel>0)
|
||||
Serial.printf("WEBLOG: %s\n",buf);
|
||||
|
||||
if(maxEntries>0){
|
||||
int index=nEntries%maxEntries;
|
||||
|
||||
log[index].upTime=esp_timer_get_time();
|
||||
if(timeInit)
|
||||
getLocalTime(&log[index].clockTime,10);
|
||||
else
|
||||
log[index].clockTime.tm_year=0;
|
||||
|
||||
log[index].message=(char *)realloc(log[index].message, strlen(buf) + 1);
|
||||
strcpy(log[index].message, buf);
|
||||
|
||||
log[index].clientIP=homeSpan.lastClientIP;
|
||||
nEntries++;
|
||||
}
|
||||
|
||||
free(log[index].message);
|
||||
vasprintf(&log[index].message,fmt,ap);
|
||||
|
||||
log[index].clientIP=homeSpan.lastClientIP;
|
||||
nEntries++;
|
||||
|
||||
if(homeSpan.logLevel>0)
|
||||
Serial.printf("WEBLOG: %s\n",log[index].message);
|
||||
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 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);
|
||||
}
|
||||
|
||||
void addWebLog(const char *fmt, ...){ // add Web Log entry
|
||||
void addWebLog(boolean sysMsg, const char *fmt, ...){ // add Web Log entry
|
||||
va_list ap;
|
||||
va_start(ap,fmt);
|
||||
webLog.vLog(fmt,ap);
|
||||
webLog.vLog(sysMsg,fmt,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 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 //
|
||||
|
|
|
|||
Loading…
Reference in New Issue