Small clean-up and formatting of comments

This commit is contained in:
Gregg 2024-02-11 18:12:19 -06:00
parent 48793eff12
commit d78abdaf6d
2 changed files with 40 additions and 48 deletions

View File

@ -215,53 +215,40 @@ void HAPClient::processRequest(){
return;
}
if(!strncmp(body,"PUT /characteristics ",21) && // PUT CHARACTERISTICS
strstr(body,"Content-Type: application/hap+json")){ // check that content is JSON
content[cLen]='\0'; // add a trailing null on end of JSON
LOG2((char *)content); // print JSON
LOG2((char *)content);
LOG2("\n------------ END JSON! ------------\n");
putCharacteristicsURL((char *)content); // process URL
return;
}
if(!strncmp(body,"PUT /characteristics ",21) && strstr(body,"Content-Type: application/hap+json")) // PUT CHARACTERISTICS
putCharacteristicsURL((char *)content);
if(!strncmp(body,"PUT /prepare ",13) && // PUT PREPARE
strstr(body,"Content-Type: application/hap+json")){ // check that content is JSON
content[cLen]='\0'; // add a trailing null on end of JSON
LOG2((char *)content); // print JSON
LOG2("\n------------ END JSON! ------------\n");
putPrepareURL((char *)content); // process URL
return;
}
else if(!strncmp(body,"PUT /prepare ",13) && strstr(body,"Content-Type: application/hap+json")) // PUT PREPARE
putPrepareURL((char *)content);
else {
notFoundError();
LOG0("\n*** ERROR: Bad PUT request - URL not found\n\n");
}
return;
} // PUT request
if(!strncmp(body,"GET ",4)){ // this is a GET request
if(!strncmp(body,"GET /accessories ",17)){ // GET ACCESSORIES
if(!strncmp(body,"GET /accessories ",17)) // GET ACCESSORIES
getAccessoriesURL();
return;
}
if(!strncmp(body,"GET /characteristics?",21)){ // GET CHARACTERISTICS
else if(!strncmp(body,"GET /characteristics?",21)) // GET CHARACTERISTICS
getCharacteristicsURL(body+21);
return;
}
if(homeSpan.webLog.isEnabled && !strncmp(body,homeSpan.webLog.statusURL.c_str(),homeSpan.webLog.statusURL.length())){ // GET STATUS - AN OPTIONAL, NON-HAP-R2 FEATURE
else if(homeSpan.webLog.isEnabled && !strncmp(body,homeSpan.webLog.statusURL.c_str(),homeSpan.webLog.statusURL.length())) // GET STATUS - AN OPTIONAL, NON-HAP-R2 FEATURE
getStatusURL(this,NULL,NULL);
return;
}
else {
notFoundError();
LOG0("\n*** ERROR: Bad GET request - URL not found\n\n");
}
return;
} // GET request
@ -1121,7 +1108,9 @@ void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char *
hapOut.setHapClient(hapClient).setLogLevel(2).setCallback(callBack).setCallbackUserData(user_data);
if(!callBack) hapOut << "HTTP/1.1 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n";
if(!callBack)
hapOut << "HTTP/1.1 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n";
hapOut << "<html><head><title>" << homeSpan.displayName << "</title>\n";
hapOut << "<style>body {background-color:lightblue;} th, td {padding-right: 10px; padding-left: 10px; border:1px solid black;}" << homeSpan.webLog.css.c_str() << "</style></head>\n";
hapOut << "<body class=bod1><h2>" << homeSpan.displayName << "</h2>\n";

View File

@ -34,7 +34,7 @@ void setup() {
Serial.begin(115200);
homeSpan.setLogLevel(1);
// homeSpan.enableWebLog(50,"pool.ntp.org","UTC",NULL);
homeSpan.enableWebLog(50,"pool.ntp.org","UTC",NULL);
// homeSpan.enableWebLog(50,"pool.ntp.org","UTC","myStatus");
// homeSpan.enableWebLog(50,NULL,NULL,NULL);
@ -72,12 +72,15 @@ void loop(){
void webLogTest(const char *dummy){
Serial.printf("\n*** In Web Log Test. Starting Custom Web Log Handler\n"); // here is where you would perform any HTTPS initializations
homeSpan.getWebLog(webLogHandler); // this starts the normal weblog with output redirected to the specified handler (below)
homeSpan.getWebLog(webLogHandler,NULL); // this starts the normal weblog with output redirected to the specified handler (below)
}
void webLogHandler(const char *buf){
if(buf!=NULL)
void webLogHandler(const char *buf, void *args){
if(buf!=NULL){
Serial.printf("--------\n");
Serial.printf("%s",buf); // here is where you would transmit data to the HTTPS connection
Serial.printf("********\n");
}
else
Serial.print("*** DONE!\n\n"); // here is where you would close the HTTPS connection
}