From 66bb13af035ba431ac577fb49ffb05506ec4657b Mon Sep 17 00:00:00 2001 From: Gregg Date: Mon, 8 May 2023 22:43:42 -0500 Subject: [PATCH] Continued change from Serial.print to LOG0() --- src/HomeSpan.cpp | 361 ++++++++++++++++++++++------------------------- src/HomeSpan.h | 20 +-- src/Network.cpp | 63 +++------ src/SRP.cpp | 5 +- src/Settings.h | 6 +- 5 files changed, 206 insertions(+), 249 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 1ff19d5..b70e27e 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -613,15 +613,11 @@ void Span::processSerialCommand(const char *c){ if(strlen(s)==4 && strlen(tBuf)==4){ sprintf(qrID,"%s",tBuf); - Serial.print("\nChanging default Setup ID for QR Code to: '"); - Serial.print(qrID); - Serial.print("'. Will take effect after next restart.\n\n"); - nvs_set_str(HAPClient::hapNVS,"SETUPID",qrID); // update data + LOG0("\nChanging default Setup ID for QR Code to: '%s'. Will take effect after next restart.\n\n",qrID); + nvs_set_str(HAPClient::hapNVS,"SETUPID",qrID); nvs_commit(HAPClient::hapNVS); } else { - Serial.print("\n*** Invalid request to change Setup ID for QR Code to: '"); - Serial.print(s); - Serial.print("'. Setup ID must be exactly 4 alphanumeric characters (0-9, A-Z, and a-z).\n\n"); + LOG0("\n*** Invalid request to change Setup ID for QR Code to: '%s'. Setup ID must be exactly 4 alphanumeric characters (0-9, A-Z, and a-z).\n\n",s); } } break; @@ -630,35 +626,33 @@ void Span::processSerialCommand(const char *c){ char textPwd[34]="\0"; - Serial.print("\n>>> New OTA Password, or to cancel request: "); + LOG0("\n>>> New OTA Password, or to cancel request: "); readSerial(textPwd,33); if(strlen(textPwd)==0){ - Serial.print("(cancelled)\n\n"); + LOG0("(cancelled)\n\n"); return; } if(strlen(textPwd)==33){ - Serial.print("\n*** Sorry, 32 character limit - request cancelled\n\n"); + LOG0("\n*** Sorry, 32 character limit - request cancelled\n\n"); return; } - Serial.print(mask(textPwd,2)); - Serial.print("\n"); + LOG0("%s\n",mask(textPwd,2).c_str()); spanOTA.setPassword(textPwd); nvs_set_str(otaNVS,"OTADATA",spanOTA.otaPwd); // update data nvs_commit(otaNVS); - Serial.print("... Accepted! Password change will take effect after next restart.\n"); + LOG0("... Accepted! Password change will take effect after next restart.\n"); if(!spanOTA.enabled) - Serial.print("... Note: OTA has not been enabled in this sketch.\n"); - Serial.print("\n"); + LOG0("... Note: OTA has not been enabled in this sketch.\n"); + LOG0("\n"); } break; case 'S': { - char buf[128]; char setupCode[10]; struct { // temporary structure to hold SRP verification code and salt stored in NVS @@ -669,23 +663,19 @@ void Span::processSerialCommand(const char *c){ sscanf(c+1," %9[0-9]",setupCode); if(strlen(setupCode)!=8){ - Serial.print("\n*** Invalid request to change Setup Code. Code must be exactly 8 digits.\n\n"); + LOG0("\n*** Invalid request to change Setup Code. Code must be exactly 8 digits.\n\n"); } else if(!network.allowedCode(setupCode)){ - Serial.print("\n*** Invalid request to change Setup Code. Code too simple.\n\n"); + LOG0("\n*** Invalid request to change Setup Code. Code too simple.\n\n"); } else { - sprintf(buf,"\n\nGenerating SRP verification data for new Setup Code: %.3s-%.2s-%.3s ... ",setupCode,setupCode+3,setupCode+5); - Serial.print(buf); + LOG0("\nGenerating SRP verification data for new Setup Code: %.3s-%.2s-%.3s ... ",setupCode,setupCode+3,setupCode+5); HAPClient::srp.createVerifyCode(setupCode,verifyData.verifyCode,verifyData.salt); // create verification code from default Setup Code and random salt nvs_set_blob(HAPClient::srpNVS,"VERIFYDATA",&verifyData,sizeof(verifyData)); // update data nvs_commit(HAPClient::srpNVS); // commit to NVS - Serial.print("New Code Saved!\n"); - - Serial.print("Setup Payload for Optional QR Code: "); - Serial.print(qrCode.get(atoi(setupCode),qrID,atoi(category))); - Serial.print("\n\n"); + LOG0("New Code Saved!\n"); + LOG0("Setup Payload for Optional QR Code: %s\n\n",qrCode.get(atoi(setupCode),qrID,atoi(category))); } } break; @@ -695,7 +685,7 @@ void Span::processSerialCommand(const char *c){ HAPClient::removeControllers(); // clear all Controller data nvs_set_blob(HAPClient::hapNVS,"CONTROLLERS",HAPClient::controllers,sizeof(HAPClient::controllers)); // update data nvs_commit(HAPClient::hapNVS); // commit to NVS - Serial.print("\n*** HomeSpan Pairing Data DELETED ***\n\n"); + LOG0("\n*** HomeSpan Pairing Data DELETED ***\n\n"); for(int i=0;iclient){ // if slot is connected @@ -706,7 +696,7 @@ void Span::processSerialCommand(const char *c){ } } - Serial.print("\nDEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n"); + LOG0("\nDEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n"); mdns_service_txt_item_set("_hap","_tcp","sf","1"); // set Status Flag = 1 (Table 6-8) if(homeSpan.pairCallback) @@ -719,7 +709,7 @@ void Span::processSerialCommand(const char *c){ case 'W': { if(strlen(network.wifiData.ssid)>0){ - Serial.print("*** Stopping all current WiFi services...\n\n"); + LOG0("*** Stopping all current WiFi services...\n\n"); hapServer->end(); MDNS.end(); WiFi.disconnect(); @@ -728,7 +718,7 @@ void Span::processSerialCommand(const char *c){ network.serialConfigure(); nvs_set_blob(wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data nvs_commit(wifiNVS); // commit to NVS - Serial.print("\n*** WiFi Credentials SAVED! Restarting ***\n\n"); + LOG0("\n*** WiFi Credentials SAVED! Restarting ***\n\n"); reboot(); } break; @@ -736,7 +726,7 @@ void Span::processSerialCommand(const char *c){ case 'A': { if(strlen(network.wifiData.ssid)>0){ - Serial.print("*** Stopping all current WiFi services...\n\n"); + LOG0("*** Stopping all current WiFi services...\n\n"); hapServer->end(); MDNS.end(); WiFi.disconnect(); @@ -750,16 +740,16 @@ void Span::processSerialCommand(const char *c){ network.apConfigure(); nvs_set_blob(wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data nvs_commit(wifiNVS); // commit to NVS - Serial.print("\n*** Credentials saved!\n"); + LOG0("\n*** Credentials saved!\n"); if(strlen(network.setupCode)){ char s[10]; sprintf(s,"S%s",network.setupCode); processSerialCommand(s); } else { - Serial.print("*** Setup Code Unchanged\n"); + LOG0("*** Setup Code Unchanged\n"); } - Serial.print("\n*** Restarting...\n\n"); + LOG0("\n*** Restarting...\n\n"); STATUS_UPDATE(start(LED_ALERT),HS_AP_TERMINATED) reboot(); } @@ -770,7 +760,7 @@ void Span::processSerialCommand(const char *c){ nvs_erase_all(wifiNVS); nvs_commit(wifiNVS); WiFi.begin("none"); - Serial.print("\n*** WiFi Credentials ERASED! Restarting...\n\n"); + LOG0("\n*** WiFi Credentials ERASED! Restarting...\n\n"); reboot(); } break; @@ -779,7 +769,7 @@ void Span::processSerialCommand(const char *c){ nvs_erase_all(charNVS); nvs_commit(charNVS); - Serial.print("\n*** Values for all saved Characteristics erased!\n\n"); + LOG0("\n*** Values for all saved Characteristics erased!\n\n"); } break; @@ -787,7 +777,7 @@ void Span::processSerialCommand(const char *c){ nvs_erase_all(HAPClient::hapNVS); nvs_commit(HAPClient::hapNVS); - Serial.print("\n*** HomeSpan Device ID and Pairing Data DELETED! Restarting...\n\n"); + LOG0("\n*** HomeSpan Device ID and Pairing Data DELETED! Restarting...\n\n"); reboot(); } break; @@ -809,7 +799,7 @@ void Span::processSerialCommand(const char *c){ nvs_erase_all(otaNVS); nvs_commit(otaNVS); WiFi.begin("none"); - Serial.print("\n*** FACTORY RESET! Restarting...\n\n"); + LOG0("\n*** FACTORY RESET! Restarting...\n\n"); reboot(); } break; @@ -817,7 +807,7 @@ void Span::processSerialCommand(const char *c){ case 'E': { nvs_flash_erase(); - Serial.print("\n*** ALL DATA ERASED! Restarting...\n\n"); + LOG0("\n*** ALL DATA ERASED! Restarting...\n\n"); reboot(); } break; @@ -832,22 +822,20 @@ void Span::processSerialCommand(const char *c){ if(level>2) level=2; - Serial.print("\n*** Log Level set to "); - Serial.print(level); - Serial.print("\n\n"); + LOG0("\n*** Log Level set to %d\n\n",level); delay(1000); setLogLevel(level); } break; case 'm': { - Serial.printf("Free Memory: %d bytes\n",heap_caps_get_free_size(MALLOC_CAP_DEFAULT)); + LOG0("Free Memory: %d bytes\n",heap_caps_get_free_size(MALLOC_CAP_DEFAULT)); } break; case 'i':{ - Serial.print("\n*** HomeSpan Info ***\n\n"); + LOG0("\n*** HomeSpan Info ***\n\n"); int nErrors=0; int nWarnings=0; @@ -856,25 +844,24 @@ void Span::processSerialCommand(const char *c){ char pNames[][7]={"PR","PW","EV","AA","TW","HD","WR"}; for(auto acc=Accessories.begin(); acc!=Accessories.end(); acc++){ - Serial.printf("\u27a4 Accessory: AID=%d\n",(*acc)->aid); + LOG0("\u27a4 Accessory: AID=%d\n",(*acc)->aid); boolean foundInfo=false; if(acc==Accessories.begin() && (*acc)->aid!=1) - Serial.printf(" *** ERROR #%d! AID of first Accessory must always be 1 ***\n",++nErrors); + LOG0(" *** ERROR #%d! AID of first Accessory must always be 1 ***\n",++nErrors); if(aidValues.find((*acc)->aid)!=aidValues.end()) - Serial.printf(" *** ERROR #%d! AID already in use for another Accessory ***\n",++nErrors); + LOG0(" *** ERROR #%d! AID already in use for another Accessory ***\n",++nErrors); aidValues.insert((*acc)->aid); for(auto svc=(*acc)->Services.begin(); svc!=(*acc)->Services.end(); svc++){ - Serial.printf(" \u279f Service %s: IID=%d, %sUUID=\"%s\"",(*svc)->hapName,(*svc)->iid,(*svc)->isCustom?"Custom-":"",(*svc)->type); - Serial.printf("\n"); + LOG0(" \u279f Service %s: IID=%d, %sUUID=\"%s\"\n",(*svc)->hapName,(*svc)->iid,(*svc)->isCustom?"Custom-":"",(*svc)->type); if(!strcmp((*svc)->type,"3E")){ foundInfo=true; if((*svc)->iid!=1) - Serial.printf(" *** ERROR #%d! The Accessory Information Service must be defined before any other Services in an Accessory ***\n",++nErrors); + LOG0(" *** ERROR #%d! The Accessory Information Service must be defined before any other Services in an Accessory ***\n",++nErrors); } else if((*acc)->aid==1) // this is an Accessory with aid=1, but it has more than just AccessoryInfo. So... isBridge=false; // ...this is not a bridge device @@ -882,45 +869,45 @@ void Span::processSerialCommand(const char *c){ unordered_set hapChar; for(auto chr=(*svc)->Characteristics.begin(); chr!=(*svc)->Characteristics.end(); chr++){ - Serial.printf(" \u21e8 Characteristic %s(%s): IID=%d, %sUUID=\"%s\", %sPerms=", + LOG0(" \u21e8 Characteristic %s(%s): IID=%d, %sUUID=\"%s\", %sPerms=", (*chr)->hapName,(*chr)->uvPrint((*chr)->value).c_str(),(*chr)->iid,(*chr)->isCustom?"Custom-":"",(*chr)->type,(*chr)->perms!=(*chr)->hapChar->perms?"Custom-":""); int foundPerms=0; for(uint8_t i=0;i<7;i++){ if((*chr)->perms & (1<format!=FORMAT::STRING && (*chr)->format!=FORMAT::BOOL && (*chr)->format!=FORMAT::DATA){ if((*chr)->validValues) - Serial.printf(", Valid Values=%s",(*chr)->validValues); + LOG0(", Valid Values=%s",(*chr)->validValues); else if((*chr)->uvGet((*chr)->stepValue)>0) - Serial.printf(", %sRange=[%s,%s,%s]",(*chr)->customRange?"Custom-":"",(*chr)->uvPrint((*chr)->minValue).c_str(),(*chr)->uvPrint((*chr)->maxValue).c_str(),(*chr)->uvPrint((*chr)->stepValue).c_str()); + LOG0(", %sRange=[%s,%s,%s]",(*chr)->customRange?"Custom-":"",(*chr)->uvPrint((*chr)->minValue).c_str(),(*chr)->uvPrint((*chr)->maxValue).c_str(),(*chr)->uvPrint((*chr)->stepValue).c_str()); else - Serial.printf(", %sRange=[%s,%s]",(*chr)->customRange?"Custom-":"",(*chr)->uvPrint((*chr)->minValue).c_str(),(*chr)->uvPrint((*chr)->maxValue).c_str()); + LOG0(", %sRange=[%s,%s]",(*chr)->customRange?"Custom-":"",(*chr)->uvPrint((*chr)->minValue).c_str(),(*chr)->uvPrint((*chr)->maxValue).c_str()); } if((*chr)->nvsKey) - Serial.printf(" (nvs)"); - Serial.printf("\n"); + LOG0(" (nvs)"); + LOG0("\n"); if(!(*chr)->isCustom && !(*svc)->isCustom && (*svc)->req.find((*chr)->hapChar)==(*svc)->req.end() && (*svc)->opt.find((*chr)->hapChar)==(*svc)->opt.end()) - Serial.printf(" *** WARNING #%d! Service does not support this Characteristic ***\n",++nWarnings); + LOG0(" *** WARNING #%d! Service does not support this Characteristic ***\n",++nWarnings); else if(invalidUUID((*chr)->type,(*chr)->isCustom)) - Serial.printf(" *** ERROR #%d! Format of UUID is invalid ***\n",++nErrors); + LOG0(" *** ERROR #%d! Format of UUID is invalid ***\n",++nErrors); else if(hapChar.find((*chr)->hapChar)!=hapChar.end()) - Serial.printf(" *** ERROR #%d! Characteristic already defined for this Service ***\n",++nErrors); + LOG0(" *** ERROR #%d! Characteristic already defined for this Service ***\n",++nErrors); if((*chr)->setRangeError) - Serial.printf(" *** WARNING #%d! Attempt to set Custom Range for this Characteristic ignored ***\n",++nWarnings); + LOG0(" *** WARNING #%d! Attempt to set Custom Range for this Characteristic ignored ***\n",++nWarnings); if((*chr)->setValidValuesError) - Serial.printf(" *** WARNING #%d! Attempt to set Custom Valid Values for this Characteristic ignored ***\n",++nWarnings); + LOG0(" *** WARNING #%d! Attempt to set Custom Valid Values for this Characteristic ignored ***\n",++nWarnings); if((*chr)->format!=STRING && ((*chr)->uvGet((*chr)->value) < (*chr)->uvGet((*chr)->minValue) || (*chr)->uvGet((*chr)->value) > (*chr)->uvGet((*chr)->maxValue))) - Serial.printf(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet((*chr)->value),(*chr)->uvGet((*chr)->minValue),(*chr)->uvGet((*chr)->maxValue)); + LOG0(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet((*chr)->value),(*chr)->uvGet((*chr)->minValue),(*chr)->uvGet((*chr)->maxValue)); hapChar.insert((*chr)->hapChar); @@ -928,65 +915,65 @@ void Span::processSerialCommand(const char *c){ for(auto req=(*svc)->req.begin(); req!=(*svc)->req.end(); req++){ if(hapChar.find(*req)==hapChar.end()) - Serial.printf(" *** WARNING #%d! Required '%s' Characteristic for this Service not found ***\n",++nWarnings,(*req)->hapName); + LOG0(" *** WARNING #%d! Required '%s' Characteristic for this Service not found ***\n",++nWarnings,(*req)->hapName); } for(auto button=PushButtons.begin(); button!=PushButtons.end(); button++){ if((*button)->service==(*svc)){ if((*button)->buttonType==SpanButton::HS_BUTTON) - Serial.printf(" \u25bc SpanButton: Pin=%d, Single=%ums, Double=%ums, Long=%ums, Type=",(*button)->pin,(*button)->singleTime,(*button)->doubleTime,(*button)->longTime); + LOG0(" \u25bc SpanButton: Pin=%d, Single=%ums, Double=%ums, Long=%ums, Type=",(*button)->pin,(*button)->singleTime,(*button)->doubleTime,(*button)->longTime); else - Serial.printf(" \u25bc SpanToggle: Pin=%d, Toggle=%ums, Type=",(*button)->pin,(*button)->longTime); + LOG0(" \u25bc SpanToggle: Pin=%d, Toggle=%ums, Type=",(*button)->pin,(*button)->longTime); if((*button)->triggerType==PushButton::TRIGGER_ON_LOW) - Serial.printf("TRIGGER_ON_LOW\n"); + LOG0("TRIGGER_ON_LOW\n"); else if((*button)->triggerType==PushButton::TRIGGER_ON_HIGH) - Serial.printf("TRIGGER_ON_HIGH\n"); + LOG0("TRIGGER_ON_HIGH\n"); #if SOC_TOUCH_SENSOR_NUM > 0 else if((*button)->triggerType==PushButton::TRIGGER_ON_TOUCH) - Serial.printf("TRIGGER_ON_TOUCH\n"); + LOG0("TRIGGER_ON_TOUCH\n"); #endif else - Serial.printf("USER-DEFINED\n"); + LOG0("USER-DEFINED\n"); if((void(*)(int,int))((*svc)->*(&SpanService::button))==(void(*)(int,int))(&SpanService::button)) - Serial.printf(" *** WARNING #%d! No button() method defined in this Service ***\n",++nWarnings); + LOG0(" *** WARNING #%d! No button() method defined in this Service ***\n",++nWarnings); } } } // Services if(!foundInfo) - Serial.printf(" *** ERROR #%d! Required 'AccessoryInformation' Service not found ***\n",++nErrors); + LOG0(" *** ERROR #%d! Required 'AccessoryInformation' Service not found ***\n",++nErrors); } // Accessories - Serial.printf("\nConfigured as Bridge: %s\n",isBridge?"YES":"NO"); + LOG0("\nConfigured as Bridge: %s\n",isBridge?"YES":"NO"); if(hapConfig.configNumber>0) - Serial.printf("Configuration Number: %d\n",hapConfig.configNumber); - Serial.printf("\nDatabase Validation: Warnings=%d, Errors=%d\n\n",nWarnings,nErrors); + LOG0("Configuration Number: %d\n",hapConfig.configNumber); + LOG0("\nDatabase Validation: Warnings=%d, Errors=%d\n\n",nWarnings,nErrors); char d[]="------------------------------"; - Serial.printf("%-30s %8s %10s %s %s %s %s %s\n","Service","UUID","AID","IID","Update","Loop","Button","Linked Services"); - Serial.printf("%.30s %.8s %.10s %.3s %.6s %.4s %.6s %.15s\n",d,d,d,d,d,d,d,d); + LOG0("%-30s %8s %10s %s %s %s %s %s\n","Service","UUID","AID","IID","Update","Loop","Button","Linked Services"); + LOG0("%.30s %.8s %.10s %.3s %.6s %.4s %.6s %.15s\n",d,d,d,d,d,d,d,d); for(int i=0;iServices.size();j++){ SpanService *s=Accessories[i]->Services[j]; - Serial.printf("%-30s %8.8s %10u %3d %6s %4s %6s ",s->hapName,s->type,Accessories[i]->aid,s->iid, + LOG0("%-30s %8.8s %10u %3d %6s %4s %6s ",s->hapName,s->type,Accessories[i]->aid,s->iid, (void(*)())(s->*(&SpanService::update))!=(void(*)())(&SpanService::update)?"YES":"NO", (void(*)())(s->*(&SpanService::loop))!=(void(*)())(&SpanService::loop)?"YES":"NO", (void(*)(int,boolean))(s->*(&SpanService::button))!=(void(*)(int,boolean))(&SpanService::button)?"YES":"NO" ); if(s->linkedServices.empty()) - Serial.print("-"); + LOG0("-"); for(int k=0;klinkedServices.size();k++){ - Serial.print(s->linkedServices[k]->iid); + LOG0("%d",s->linkedServices[k]->iid); if(klinkedServices.size()-1) - Serial.print(","); + LOG0(","); } - Serial.print("\n"); + LOG0("\n"); } } @@ -994,75 +981,75 @@ void Span::processSerialCommand(const char *c){ uint8_t channel; wifi_second_chan_t channel2; esp_wifi_get_channel(&channel,&channel2); - Serial.printf("\nFound %d SpanPoint Links:\n\n",SpanPoint::SpanPoints.size()); - Serial.printf("%-17s %18s %7s %7s %7s\n","Local MAC Address","Remote MAC Address","Send","Receive","Depth"); - Serial.printf("%.17s %.18s %.7s %.7s %.7s\n",d,d,d,d,d); + LOG0("\nFound %d SpanPoint Links:\n\n",SpanPoint::SpanPoints.size()); + LOG0("%-17s %18s %7s %7s %7s\n","Local MAC Address","Remote MAC Address","Send","Receive","Depth"); + LOG0("%.17s %.18s %.7s %.7s %.7s\n",d,d,d,d,d); for(auto it=SpanPoint::SpanPoints.begin();it!=SpanPoint::SpanPoints.end();it++) - Serial.printf("%-18s %02X:%02X:%02X:%02X:%02X:%02X %7d %7d %7d\n",(*it)->peerInfo.ifidx==WIFI_IF_AP?WiFi.softAPmacAddress().c_str():WiFi.macAddress().c_str(), + LOG0("%-18s %02X:%02X:%02X:%02X:%02X:%02X %7d %7d %7d\n",(*it)->peerInfo.ifidx==WIFI_IF_AP?WiFi.softAPmacAddress().c_str():WiFi.macAddress().c_str(), (*it)->peerInfo.peer_addr[0],(*it)->peerInfo.peer_addr[1],(*it)->peerInfo.peer_addr[2],(*it)->peerInfo.peer_addr[3],(*it)->peerInfo.peer_addr[4],(*it)->peerInfo.peer_addr[5], (*it)->sendSize,(*it)->receiveSize,uxQueueSpacesAvailable((*it)->receiveQueue)); - Serial.printf("\nSpanPoint using WiFi Channel %d%s\n",channel,WiFi.status()!=WL_CONNECTED?" (subject to change once WiFi connection established)":""); + LOG0("\nSpanPoint using WiFi Channel %d%s\n",channel,WiFi.status()!=WL_CONNECTED?" (subject to change once WiFi connection established)":""); } - Serial.print("\n*** End Info ***\n\n"); + LOG0("\n*** End Info ***\n\n"); } break; case 'P': { - Serial.printf("\n*** Pairing Data used for Cloning another Device\n\n"); + LOG0("\n*** Pairing Data used for Cloning another Device\n\n"); size_t olen; TempBuffer tBuf(256); mbedtls_base64_encode((uint8_t *)tBuf.buf,256,&olen,(uint8_t *)&HAPClient::accessory,sizeof(struct Accessory)); - Serial.printf("Accessory data: %s\n",tBuf.buf); + LOG0("Accessory data: %s\n",tBuf.buf); for(int i=0;i tBuf(200); size_t olen; tBuf.buf[0]='\0'; - Serial.print(">>> Accessory data: "); + LOG0(">>> Accessory data: "); readSerial(tBuf.buf,199); if(strlen(tBuf.buf)==0){ - Serial.printf("(cancelled)\n\n"); + LOG0("(cancelled)\n\n"); return; } mbedtls_base64_decode((uint8_t *)&HAPClient::accessory,sizeof(struct Accessory),&olen,(uint8_t *)tBuf.buf,strlen(tBuf.buf)); if(olen!=sizeof(struct Accessory)){ - Serial.printf("\n*** Error in size of Accessory data - cloning cancelled. Restarting...\n\n"); + LOG0("\n*** Error in size of Accessory data - cloning cancelled. Restarting...\n\n"); reboot(); } else { HAPClient::charPrintRow(HAPClient::accessory.ID,17); - Serial.printf("\n"); + LOG0("\n"); } for(int i=0;i>> Controller data: "); + LOG0(">>> Controller data: "); readSerial(tBuf.buf,199); if(strlen(tBuf.buf)==0){ - Serial.printf("(done)\n"); + LOG0("(done)\n"); while(i - change the HomeKit Pairing Setup Code to \n"); - Serial.print(" Q - change the HomeKit Setup ID for QR Codes to \n"); - Serial.print(" O - change the OTA password\n"); - Serial.print(" A - start the HomeSpan Setup Access Point\n"); - Serial.print("\n"); - Serial.print(" V - delete value settings for all saved Characteristics\n"); - Serial.print(" U - unpair device by deleting all Controller data\n"); - Serial.print(" H - delete HomeKit Device ID as well as all Controller data and restart\n"); - Serial.print("\n"); - Serial.print(" P - output Pairing Data that can be saved offline to clone a new device\n"); - Serial.print(" C - clone Pairing Data previously saved offline from another device\n"); - Serial.print("\n"); - Serial.print(" R - restart device\n"); - Serial.print(" F - factory reset and restart\n"); - Serial.print(" E - erase ALL stored data and restart\n"); - Serial.print("\n"); - Serial.print(" L - change the Log Level setting to \n"); - Serial.print("\n"); + LOG0("\n*** HomeSpan Commands ***\n\n"); + LOG0(" s - print connection status\n"); + LOG0(" i - print summary information about the HAP Database\n"); + LOG0(" d - print the full HAP Accessory Attributes Database in JSON format\n"); + LOG0(" m - print free heap memory\n"); + LOG0("\n"); + LOG0(" W - configure WiFi Credentials and restart\n"); + LOG0(" X - delete WiFi Credentials and restart\n"); + LOG0(" S - change the HomeKit Pairing Setup Code to \n"); + LOG0(" Q - change the HomeKit Setup ID for QR Codes to \n"); + LOG0(" O - change the OTA password\n"); + LOG0(" A - start the HomeSpan Setup Access Point\n"); + LOG0("\n"); + LOG0(" V - delete value settings for all saved Characteristics\n"); + LOG0(" U - unpair device by deleting all Controller data\n"); + LOG0(" H - delete HomeKit Device ID as well as all Controller data and restart\n"); + LOG0("\n"); + LOG0(" P - output Pairing Data that can be saved offline to clone a new device\n"); + LOG0(" C - clone Pairing Data previously saved offline from another device\n"); + LOG0("\n"); + LOG0(" R - restart device\n"); + LOG0(" F - factory reset and restart\n"); + LOG0(" E - erase ALL stored data and restart\n"); + LOG0("\n"); + LOG0(" L - change the Log Level setting to \n"); + LOG0("\n"); for(auto uCom=homeSpan.UserCommands.begin(); uCom!=homeSpan.UserCommands.end(); uCom++) // loop over all UserCommands using an iterator - Serial.printf(" @%c %s\n",uCom->first,uCom->second->s); + LOG0(" @%c %s\n",uCom->first,uCom->second->s); if(!homeSpan.UserCommands.empty()) - Serial.print("\n"); + LOG0("\n"); - Serial.print(" ? - print this list of commands\n\n"); - Serial.print("*** End Commands ***\n\n"); + LOG0(" ? - print this list of commands\n\n"); + LOG0("*** End Commands ***\n\n"); } break; @@ -1138,17 +1125,13 @@ void Span::processSerialCommand(const char *c){ else uCom->second->userFunction2(c+1,uCom->second->userArg); } else { - Serial.print("*** Undefined user command: '"); - Serial.print(c); - Serial.print("'. Type '?' for list of commands.\n"); + LOG0("*** Undefined user command: '%s'. Type '?' for list of commands.\n",c); } } break; default: - Serial.print("*** Unknown command: '"); - Serial.print(c); - Serial.print("'. Type '?' for list of commands.\n"); + LOG0("*** Unknown command: '%s'. Type '?' for list of commands.\n",c); break; } // switch @@ -1244,37 +1227,35 @@ void Span::prettyPrint(char *buf, int nsp){ case '{': case '[': - Serial.print(buf[i]); - Serial.print("\n"); + LOG0("%c\n",buf[i]); indent+=nsp; for(int j=0;jTimedWrites[pid]){ - Serial.print("\n*** ERROR: Timed Write Expired\n\n"); + LOG0("\n*** ERROR: Timed Write Expired\n\n"); twFail=true; } } else { - Serial.print("\n*** ERROR: Problems parsing JSON characteristics object - unexpected property \""); - Serial.print(t2); - Serial.print("\"\n\n"); + LOG0("\n*** ERROR: Problems parsing JSON characteristics object - unexpected property \"%s\"\n\n",t2); return(0); } } // parse property tokens @@ -1397,7 +1376,7 @@ int Span::updateCharacteristics(char *buf, SpanBuf *pObj){ if(okay==7 || okay==11 || okay==15){ // all required properties found nObj++; // increment number of characteristic objects found } else { - Serial.print("\n*** ERROR: Problems parsing JSON characteristics object - missing required properties\n\n"); + LOG0("\n*** ERROR: Problems parsing JSON characteristics object - missing required properties\n\n"); return(0); } } @@ -1626,9 +1605,7 @@ SpanAccessory::SpanAccessory(uint32_t aid){ if(!homeSpan.Accessories.empty()){ if(homeSpan.Accessories.size()==HAPClient::MAX_ACCESSORIES){ - Serial.print("\n\n*** FATAL ERROR: Can't create more than "); - Serial.print(HAPClient::MAX_ACCESSORIES); - Serial.print(" Accessories. Program Halting.\n\n"); + LOG0("\n\n*** FATAL ERROR: Can't create more than %d Accessories. Program Halting.\n\n",HAPClient::MAX_ACCESSORIES); while(1); } @@ -1685,8 +1662,8 @@ int SpanAccessory::sprintfAttributes(char *cBuf, int flags){ SpanService::SpanService(const char *type, const char *hapName, boolean isCustom){ if(homeSpan.Accessories.empty()){ - Serial.printf("\nFATAL ERROR! Can't create new Service '%s' without a defined Accessory ***\n",hapName); - Serial.printf("\n=== PROGRAM HALTED ==="); + LOG0("\nFATAL ERROR! Can't create new Service '%s' without a defined Accessory ***\n",hapName); + LOG0("\n=== PROGRAM HALTED ==="); while(1); } @@ -1803,8 +1780,8 @@ SpanCharacteristic::SpanCharacteristic(HapChar *hapChar, boolean isCustom){ this->hapChar=hapChar; if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){ - Serial.printf("\nFATAL ERROR! Can't create new Characteristic '%s' without a defined Service ***\n",hapName); - Serial.printf("\n=== PROGRAM HALTED ==="); + LOG0("\nFATAL ERROR! Can't create new Characteristic '%s' without a defined Service ***\n",hapName); + LOG0("\n=== PROGRAM HALTED ==="); while(1); } @@ -2068,8 +2045,8 @@ SpanCharacteristic *SpanCharacteristic::setValidValues(int n, ...){ SpanRange::SpanRange(int min, int max, int step){ if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty() || homeSpan.Accessories.back()->Services.back()->Characteristics.empty() ){ - Serial.printf("\nFATAL ERROR! Can't create new SpanRange(%d,%d,%d) without a defined Characteristic ***\n",min,max,step); - Serial.printf("\n=== PROGRAM HALTED ==="); + LOG0("\nFATAL ERROR! Can't create new SpanRange(%d,%d,%d) without a defined Characteristic ***\n",min,max,step); + LOG0("\n=== PROGRAM HALTED ==="); while(1); } else { homeSpan.Accessories.back()->Services.back()->Characteristics.back()->setRange(min,max,step); @@ -2084,11 +2061,11 @@ SpanButton::SpanButton(int pin, uint16_t longTime, uint16_t singleTime, uint16_t if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){ if(buttonType==HS_BUTTON) - Serial.printf("\nFATAL ERROR! Can't create new SpanButton(%d,%u,%u,%u) without a defined Service ***\n",pin,longTime,singleTime,doubleTime); + LOG0("\nFATAL ERROR! Can't create new SpanButton(%d,%u,%u,%u) without a defined Service ***\n",pin,longTime,singleTime,doubleTime); else - Serial.printf("\nFATAL ERROR! Can't create new SpanToggle(%d,%u) without a defined Service ***\n",pin,longTime); + LOG0("\nFATAL ERROR! Can't create new SpanToggle(%d,%u) without a defined Service ***\n",pin,longTime); - Serial.printf("\n=== PROGRAM HALTED ==="); + LOG0("\n=== PROGRAM HALTED ==="); while(1); } @@ -2173,9 +2150,9 @@ void SpanWebLog::vLog(boolean sysMsg, const char *fmt, va_list ap){ vasprintf(&buf,fmt,ap); if(sysMsg) - Serial.printf("%s\n",buf); + LOG0("%s\n",buf); else if(homeSpan.logLevel>0) - Serial.printf("WEBLOG: %s\n",buf); + LOG0("WEBLOG: %s\n",buf); if(maxEntries>0){ int index=nEntries%maxEntries; @@ -2202,7 +2179,7 @@ void SpanWebLog::vLog(boolean sysMsg, const char *fmt, va_list ap){ int SpanOTA::init(boolean _auth, boolean _safeLoad, const char *pwd){ if(esp_ota_get_running_partition()==esp_ota_get_next_update_partition(NULL)){ - Serial.print("\n*** WARNING: Can't start OTA Server - Partition table used to compile this sketch is not configured for OTA.\n\n"); + LOG0("\n*** WARNING: Can't start OTA Server - Partition table used to compile this sketch is not configured for OTA.\n\n"); return(-1); } @@ -2219,7 +2196,7 @@ int SpanOTA::init(boolean _auth, boolean _safeLoad, const char *pwd){ int SpanOTA::setPassword(const char *pwd){ if(strlen(pwd)<1 || strlen(pwd)>32){ - Serial.printf("\n*** WARNING: Cannot change OTA password to '%s'. Password length must be between 1 and 32 characters.\n\n",pwd); + LOG0("\n*** WARNING: Cannot change OTA password to '%s'. Password length must be between 1 and 32 characters.\n\n",pwd); return(-1); } @@ -2234,7 +2211,7 @@ int SpanOTA::setPassword(const char *pwd){ /////////////////////////////// void SpanOTA::start(){ - Serial.printf("\n*** Current Partition: %s\n*** New Partition: %s\n*** OTA Starting..", + LOG0("\n*** Current Partition: %s\n*** New Partition: %s\n*** OTA Starting..", esp_ota_get_running_partition()->label,esp_ota_get_next_update_partition(NULL)->label); otaPercent=0; STATUS_UPDATE(start(LED_OTA_STARTED),HS_OTA_STARTED) @@ -2245,7 +2222,7 @@ void SpanOTA::start(){ void SpanOTA::end(){ nvs_set_u8(homeSpan.otaNVS,"OTA_REQUIRED",safeLoad); nvs_commit(homeSpan.otaNVS); - Serial.printf(" DONE! Rebooting...\n"); + LOG0(" DONE! Rebooting...\n"); homeSpan.reboot(); } @@ -2255,13 +2232,13 @@ void SpanOTA::progress(uint32_t progress, uint32_t total){ int percent=progress*100/total; if(percent/10 != otaPercent/10){ otaPercent=percent; - Serial.printf("%d%%..",progress*100/total); + LOG0("%d%%..",progress*100/total); } if(safeLoad && progress==total){ SpanPartition newSpanPartition; esp_partition_read(esp_ota_get_next_update_partition(NULL), sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) + sizeof(esp_app_desc_t), &newSpanPartition, sizeof(newSpanPartition)); - Serial.printf("Checking for HomeSpan Magic Cookie: %s..",newSpanPartition.magicCookie); + LOG0("Checking for HomeSpan Magic Cookie: %s..",newSpanPartition.magicCookie); if(strcmp(newSpanPartition.magicCookie,spanPartition.magicCookie)) Update.abort(); } @@ -2270,12 +2247,12 @@ void SpanOTA::progress(uint32_t progress, uint32_t total){ /////////////////////////////// void SpanOTA::error(ota_error_t err){ - Serial.printf("*** OTA Error[%u]: ", err); - if (err == OTA_AUTH_ERROR) Serial.println("Auth Failed\n"); - else if (err == OTA_BEGIN_ERROR) Serial.println("Begin Failed\n"); - else if (err == OTA_CONNECT_ERROR) Serial.println("Connect Failed\n"); - else if (err == OTA_RECEIVE_ERROR) Serial.println("Receive Failed\n"); - else if (err == OTA_END_ERROR) Serial.println("End Failed\n"); + LOG0("*** OTA Error[%u]: ", err); + if (err == OTA_AUTH_ERROR) LOG0("Auth Failed\n\n"); + else if (err == OTA_BEGIN_ERROR) LOG0("Begin Failed\n\n"); + else if (err == OTA_CONNECT_ERROR) LOG0("Connect Failed\n\n"); + else if (err == OTA_RECEIVE_ERROR) LOG0("Receive Failed\n\n"); + else if (err == OTA_END_ERROR) LOG0("End Failed\n\n"); } /////////////////////////////// @@ -2292,14 +2269,14 @@ boolean SpanOTA::auth; SpanPoint::SpanPoint(const char *macAddress, int sendSize, int receiveSize, int queueDepth, boolean useAPaddress){ if(sscanf(macAddress,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",peerInfo.peer_addr,peerInfo.peer_addr+1,peerInfo.peer_addr+2,peerInfo.peer_addr+3,peerInfo.peer_addr+4,peerInfo.peer_addr+5)!=6){ - Serial.printf("\nFATAL ERROR! Can't create new SpanPoint(\"%s\") - Invalid MAC Address ***\n",macAddress); - Serial.printf("\n=== PROGRAM HALTED ==="); + LOG0("\nFATAL ERROR! Can't create new SpanPoint(\"%s\") - Invalid MAC Address ***\n",macAddress); + LOG0("\n=== PROGRAM HALTED ==="); while(1); } if(sendSize<0 || sendSize>200 || receiveSize<0 || receiveSize>200 || queueDepth<1 || (sendSize==0 && receiveSize==0)){ - Serial.printf("\nFATAL ERROR! Can't create new SpanPoint(\"%s\",%d,%d,%d) - one or more invalid parameters ***\n",macAddress,sendSize,receiveSize,queueDepth); - Serial.printf("\n=== PROGRAM HALTED ==="); + LOG0("\nFATAL ERROR! Can't create new SpanPoint(\"%s\",%d,%d,%d) - one or more invalid parameters ***\n",macAddress,sendSize,receiveSize,queueDepth); + LOG0("\n=== PROGRAM HALTED ==="); while(1); } @@ -2380,8 +2357,8 @@ void SpanPoint::setChannelMask(uint16_t mask){ channel=(channelMask & (1<receiveSize){ - Serial.printf("SpanPoint Warning! %d bytes received from %02X:%02X:%02X:%02X:%02X:%02X does not match %d-byte queue size\n",len,mac[0],mac[1],mac[2],mac[3],mac[4],mac[5],(*it)->receiveSize); + LOG0("SpanPoint Warning! %d bytes received from %02X:%02X:%02X:%02X:%02X:%02X does not match %d-byte queue size\n",len,mac[0],mac[1],mac[2],mac[3],mac[4],mac[5],(*it)->receiveSize); return; } diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 53f5f0b..392da50 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -346,7 +346,7 @@ class Span{ void autoPoll(uint32_t stackSize=8192, uint32_t priority=1, uint32_t cpu=0){ // start pollTask() xTaskCreateUniversal([](void *parms){for(;;)homeSpan.pollTask();}, "pollTask", stackSize, NULL, priority, &pollTaskHandle, cpu); - Serial.printf("\n*** AutoPolling Task started with priority=%d\n\n",uxTaskPriorityGet(pollTaskHandle)); + LOG0("\n*** AutoPolling Task started with priority=%d\n\n",uxTaskPriorityGet(pollTaskHandle)); } void setTimeServerTimeout(uint32_t tSec){webLog.waitTime=tSec*1000;} // sets wait time (in seconds) for optional web log time server to connect @@ -635,7 +635,7 @@ class SpanCharacteristic{ void setString(const char *val){ if((perms & EV) == 0){ - Serial.printf("\n*** WARNING: Attempt to update Characteristic::%s with setString() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName); + LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setString() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName); return; } @@ -669,9 +669,9 @@ class SpanCharacteristic{ return(olen); if(ret==MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) - Serial.printf("\n*** WARNING: Can't decode Characteristic::%s with getData(). Destination buffer is too small (%d out of %d bytes needed)\n\n",hapName,len,olen); + LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Destination buffer is too small (%d out of %d bytes needed)\n\n",hapName,len,olen); else if(ret==MBEDTLS_ERR_BASE64_INVALID_CHARACTER) - Serial.printf("\n*** WARNING: Can't decode Characteristic::%s with getData(). Data is not in base-64 format\n\n",hapName); + LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Data is not in base-64 format\n\n",hapName); return(olen); } @@ -687,9 +687,9 @@ class SpanCharacteristic{ return(olen); if(ret==MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) - Serial.printf("\n*** WARNING: Can't decode Characteristic::%s with getData(). Destination buffer is too small (%d out of %d bytes needed)\n\n",hapName,len,olen); + LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Destination buffer is too small (%d out of %d bytes needed)\n\n",hapName,len,olen); else if(ret==MBEDTLS_ERR_BASE64_INVALID_CHARACTER) - Serial.printf("\n*** WARNING: Can't decode Characteristic::%s with getData(). Data is not in base-64 format\n\n",hapName); + LOG0("\n*** WARNING: Can't decode Characteristic::%s with getData(). Data is not in base-64 format\n\n",hapName); return(olen); } @@ -697,12 +697,12 @@ class SpanCharacteristic{ void setData(uint8_t *data, size_t len){ if((perms & EV) == 0){ - Serial.printf("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName); + LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName); return; } if(len<1){ - Serial.printf("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. Size of data buffer must be greater than zero\n\n",hapName); + LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setData() ignored. Size of data buffer must be greater than zero\n\n",hapName); return; } @@ -716,12 +716,12 @@ class SpanCharacteristic{ template void setVal(T val, boolean notify=true){ if((perms & EV) == 0){ - Serial.printf("\n*** WARNING: Attempt to update Characteristic::%s with setVal() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName); + LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName); return; } if(val < uvGet(minValue) || val > uvGet(maxValue)){ - Serial.printf("\n*** WARNING: Attempt to update Characteristic::%s with setVal(%g) is out of range [%g,%g]. This may cause device to become non-reponsive!\n\n", + LOG0("\n*** WARNING: Attempt to update Characteristic::%s with setVal(%g) is out of range [%g,%g]. This may cause device to become non-reponsive!\n\n", hapName,(double)val,uvGet(minValue),uvGet(maxValue)); } diff --git a/src/Network.cpp b/src/Network.cpp index a5f452f..bcfe676 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -65,33 +65,26 @@ void Network::serialConfigure(){ wifiData.ssid[0]='\0'; wifiData.pwd[0]='\0'; - Serial.print("*** WiFi Setup - Scanning for Networks...\n\n"); + LOG0("*** WiFi Setup - Scanning for Networks...\n\n"); scan(); // scan for networks - for(int i=0;i>> WiFi SSID: "); + LOG0("\n>>> WiFi SSID: "); readSerial(wifiData.ssid,MAX_SSID); if(atoi(wifiData.ssid)>0 && atoi(wifiData.ssid)<=numSSID){ strcpy(wifiData.ssid,ssidList[atoi(wifiData.ssid)-1]); } - Serial.print(wifiData.ssid); - Serial.print("\n"); + LOG0("%s\n",wifiData.ssid); } while(!strlen(wifiData.pwd)){ - Serial.print(">>> WiFi PASS: "); + LOG0(">>> WiFi PASS: "); readSerial(wifiData.pwd,MAX_PWD); - Serial.print(mask(wifiData.pwd,2)); - Serial.print("\n"); + LOG0("%s\n",mask(wifiData.pwd,2).c_str()); } return; @@ -110,25 +103,16 @@ boolean Network::allowedCode(char *s){ void Network::apConfigure(){ - Serial.print("*** Starting Access Point: "); - Serial.print(apSSID); - Serial.print(" / "); - Serial.print(apPassword); - Serial.print("\n"); + LOG0("*** Starting Access Point: %s / %s\n",apSSID,apPassword); STATUS_UPDATE(start(LED_AP_STARTED),HS_AP_STARTED) - Serial.print("\nScanning for Networks...\n\n"); + LOG0("\nScanning for Networks...\n\n"); scan(); // scan for networks - for(int i=0;itriggered(9999,3000)){ - Serial.print("\n*** Access Point Terminated. Restarting...\n\n"); + LOG0("\n*** Access Point Terminated. Restarting...\n\n"); STATUS_UPDATE(start(LED_ALERT),HS_AP_TERMINATED) homeSpan.controlButton->wait(); homeSpan.reboot(); @@ -163,17 +147,14 @@ void Network::apConfigure(){ WiFi.softAPdisconnect(true); // terminate connections and shut down captive access point delay(100); if(apStatus==1){ - Serial.print("\n*** Access Point: Exiting and Saving Settings\n\n"); + LOG0("\n*** Access Point: Exiting and Saving Settings\n\n"); return; } else { - if(apStatus==0){ - Serial.print("\n*** Access Point: Timed Out ("); - Serial.print(lifetime/1000); - Serial.print(" seconds)."); - } else { - Serial.print("\n*** Access Point: Configuration Cancelled."); - } - Serial.print(" Restarting...\n\n"); + if(apStatus==0) + LOG0("\n*** Access Point: Timed Out (%ld seconds).",lifetime/1000); + else + LOG0("\n*** Access Point: Configuration Cancelled."); + LOG0(" Restarting...\n\n"); STATUS_UPDATE(start(LED_ALERT),HS_AP_TERMINATED) homeSpan.reboot(); } @@ -202,7 +183,7 @@ void Network::apConfigure(){ if(nBytes>MAX_HTTP){ // exceeded maximum number of bytes allowed badRequestError(); - Serial.print("\n*** ERROR: Exceeded maximum HTTP message length\n\n"); + LOG0("\n*** ERROR: Exceeded maximum HTTP message length\n\n"); continue; } @@ -212,7 +193,7 @@ void Network::apConfigure(){ if(!(p=strstr((char *)httpBuf,"\r\n\r\n"))){ badRequestError(); - Serial.print("\n*** ERROR: Malformed HTTP request (can't find blank line indicating end of BODY)\n\n"); + LOG0("\n*** ERROR: Malformed HTTP request (can't find blank line indicating end of BODY)\n\n"); continue; } @@ -224,7 +205,7 @@ void Network::apConfigure(){ cLen=atoi(p+16); if(nBytes!=strlen(body)+4+cLen){ badRequestError(); - Serial.print("\n*** ERROR: Malformed HTTP request (Content-Length plus Body Length does not equal total number of bytes read)\n\n"); + LOG0("\n*** ERROR: Malformed HTTP request (Content-Length plus Body Length does not equal total number of bytes read)\n\n"); continue; } diff --git a/src/SRP.cpp b/src/SRP.cpp index bc03cd7..812224e 100644 --- a/src/SRP.cpp +++ b/src/SRP.cpp @@ -273,9 +273,8 @@ void SRP6A::print(mbedtls_mpi *mpi){ mbedtls_mpi_write_string(mpi,16,sBuf,2000,&sLen); - Serial.print((sLen-1)/2); // subtract 1 for null-terminator, and then divide by 2 to get number of bytes (e.g. 4F = 2 characters, but represents just one mpi byte) - Serial.print(" "); - Serial.println(sBuf); + LOG0("%d ",(sLen-1)/2); // subtract 1 for null-terminator, and then divide by 2 to get number of bytes (e.g. 4F = 2 characters, but represents just one mpi byte) + LOG0("%s\n",sBuf); } ////////////////////////////////////// diff --git a/src/Settings.h b/src/Settings.h index 9981f08..7cafe34 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -104,9 +104,9 @@ // Message Log Level Control Macros // // 0=Minimal, 1=Informative, 2=All // -#define LOG0(format,...) if(homeSpan.getLogLevel()>=0)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__) -#define LOG1(format,...) if(homeSpan.getLogLevel()>=1)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__) -#define LOG2(format,...) if(homeSpan.getLogLevel()>=2)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__) +#define LOG0(format,...) do{ if(homeSpan.getLogLevel()>=0)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__); }while(0) +#define LOG1(format,...) do{ if(homeSpan.getLogLevel()>=1)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__); }while(0) +#define LOG2(format,...) do{ if(homeSpan.getLogLevel()>=2)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__); }while(0) #define WEBLOG(format,...) homeSpan.addWebLog(false, format __VA_OPT__(,) __VA_ARGS__);