Added ClientIP as permanent part of Web Log ; DELETED homeSpan.getClientIP()

ClientIP will show as "0.0.0.0" if log message is not related to client request
This commit is contained in:
Gregg 2022-03-05 22:24:23 -06:00
parent cf22ff1a92
commit f37889f8da
4 changed files with 7 additions and 5 deletions

View File

@ -18,6 +18,7 @@ struct DEV_LED : Service::LightBulb { // First we create a derived
power=new Characteristic::On(); // this is where we create the On Characterstic we had previously defined in setup(). Save this in the pointer created above, for use below
this->ledPin=ledPin; // don't forget to store ledPin...
pinMode(ledPin,OUTPUT); // ...and set the mode for ledPin to be an OUTPUT (standard Arduino function)
WEBLOG("Configuring LED on Pin %d",ledPin);
} // end constructor
@ -26,7 +27,7 @@ struct DEV_LED : Service::LightBulb { // First we create a derived
boolean update(){
digitalWrite(ledPin,power->getNewVal()); // use a standard Arduino function to turn on/off ledPin based on the return of a call to power->getNewVal() (see below for more info)
WEBLOG("LED on Pin %d: %s (%s)",ledPin,power->getNewVal()?"ON":"OFF",homeSpan.getClientIP());
WEBLOG("LED on Pin %d: %s",ledPin,power->getNewVal()?"ON":"OFF");
return(true); // return true to indicate the update was successful (otherwise create code to return false if some reason you could not turn on the LED)

View File

@ -1297,7 +1297,7 @@ int HAPClient::getStatusURL(){
response+="<p></p>";
if(homeSpan.webLog.maxEntries>0){
response+="<table><tr><th>Entry</th><th>Up Time</th><th>Log Time</th><th>Message</th></tr>\n";
response+="<table><tr><th>Entry</th><th>Up Time</th><th>Log Time</th><th>Client</th><th>Message</th></tr>\n";
int lastIndex=homeSpan.webLog.nEntries-homeSpan.webLog.maxEntries;
if(lastIndex<0)
lastIndex=0;
@ -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>\n";
response+="<tr><td>" + String(i+1) + "</td><td>" + String(uptime) + "</td><td>" + String(clocktime) + "</td><td>" + homeSpan.webLog.log[index].clientIP + "</td><td>" + String(homeSpan.webLog.log[index].message) + "</td/tr>\n";
}
response+="</table>\n";
}

View File

@ -1979,6 +1979,7 @@ void SpanWebLog::addLog(const char *fmt, ...){
va_start(ap,fmt);
vasprintf(&log[index].message,fmt,ap);
va_end(ap);
log[index].clientIP=homeSpan.lastClientIP;
nEntries++;
}

View File

@ -110,6 +110,7 @@ struct SpanWebLog{ // optional web status/log data
uint64_t upTime; // number of seconds since booting
struct tm clockTime; // clock time
char *message; // pointers to log entries of arbitrary size
String clientIP; // IP address of client making request (or "0.0.0.0" if not applicable)
} *log=NULL; // array of log entries
void init(uint16_t maxEntries, const char *serv, const char *tz, const char *url);
@ -221,7 +222,6 @@ struct Span{
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
const char *getClientIP(){return(lastClientIP.c_str());} // get IP address of last client to send an encrypted request - to be used only in update() commands
void setPairingCode(const char *s){sprintf(pairingCodeCommand,"S %9s",s);} // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS