diff --git a/src/HAP.cpp b/src/HAP.cpp index 89bdc9d..5b15003 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -342,6 +342,11 @@ void HAPClient::processRequest(){ return; } + if(!strncmp(body,"GET /status ",12)){ // GET STATUS - AN OPTIONAL, NON-HAP-R2 FEATURE + getStatusURL(); + return; + } + notFoundError(); Serial.print("\n*** ERROR: Bad GET request - URL not found\n\n"); return; @@ -1249,6 +1254,52 @@ int HAPClient::putPrepareURL(char *json){ ////////////////////////////////////// +int HAPClient::getStatusURL(){ + + char uptime[16]; + int seconds=esp_timer_get_time()/1e6; + int secs=seconds%60; + int mins=(seconds/=60)%60; + int hours=(seconds/=60)%24; + int days=(seconds/=24); + + sprintf(uptime,"%d:%02d:%02d:%02d",days,hours,mins,secs); + + String response="HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n"; + + response+="HomeSpan Status\n"; + response+="\n"; + response+="\n"; + response+="

" + String(homeSpan.displayName) + "

\n"; + + response+="\n"; + response+="\n"; + response+="\n"; + response+="\n"; + response+="\n"; + response+="\n"; + response+="\n"; + response+="
Uptime:" + String(uptime) + "
ESP32 Board:" + String(ARDUINO_BOARD) + "
Arduino-ESP Version:" + String(ARDUINO_ESP_VERSION) + "
ESP-IDF Version:" + String(ESP_IDF_VERSION_MAJOR) + "." + String(ESP_IDF_VERSION_MINOR) + "." + String(ESP_IDF_VERSION_PATCH) + "
HomeSpan Version:" + String(HOMESPAN_VERSION) + "
Sketch Version:" + String(homeSpan.getSketchVersion()) + "
\n"; + + response+=""; + + LOG2("\n>>>>>>>>>> "); + LOG2(client.remoteIP()); + LOG2(" >>>>>>>>>>\n"); + LOG2(response); + LOG2("\n"); + client.print(response); + LOG2("------------ SENT! --------------\n"); + + delay(1); + client.stop(); + + return(1); +} + +////////////////////////////////////// + void HAPClient::callServiceLoops(){ homeSpan.snapTime=millis(); // snap the current time for use in ALL loop routines @@ -1304,7 +1355,6 @@ void HAPClient::checkTimedWrites(){ ////////////////////////////////////// - void HAPClient::eventNotify(SpanBuf *pObj, int nObj, int ignoreClient){ for(int cNum=0;cNum0) void sendEncrypted(char *body, uint8_t *dataBuf, int dataLen); // send client complete ChaCha20-Poly1305 encrypted HTTP mesage comprising a null-terminated 'body' and 'dataBuf' with 'dataLen' bytes