Continued change from Serial.print to LOG0()

This commit is contained in:
Gregg 2023-05-08 22:43:42 -05:00
parent 368ce12c04
commit 66bb13af03
5 changed files with 206 additions and 249 deletions

View File

@ -613,15 +613,11 @@ void Span::processSerialCommand(const char *c){
if(strlen(s)==4 && strlen(tBuf)==4){ if(strlen(s)==4 && strlen(tBuf)==4){
sprintf(qrID,"%s",tBuf); sprintf(qrID,"%s",tBuf);
Serial.print("\nChanging default Setup ID for QR Code to: '"); LOG0("\nChanging default Setup ID for QR Code to: '%s'. Will take effect after next restart.\n\n",qrID);
Serial.print(qrID); nvs_set_str(HAPClient::hapNVS,"SETUPID",qrID);
Serial.print("'. Will take effect after next restart.\n\n");
nvs_set_str(HAPClient::hapNVS,"SETUPID",qrID); // update data
nvs_commit(HAPClient::hapNVS); nvs_commit(HAPClient::hapNVS);
} else { } else {
Serial.print("\n*** Invalid request to change Setup ID for QR Code to: '"); 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);
Serial.print(s);
Serial.print("'. Setup ID must be exactly 4 alphanumeric characters (0-9, A-Z, and a-z).\n\n");
} }
} }
break; break;
@ -630,35 +626,33 @@ void Span::processSerialCommand(const char *c){
char textPwd[34]="\0"; char textPwd[34]="\0";
Serial.print("\n>>> New OTA Password, or <return> to cancel request: "); LOG0("\n>>> New OTA Password, or <return> to cancel request: ");
readSerial(textPwd,33); readSerial(textPwd,33);
if(strlen(textPwd)==0){ if(strlen(textPwd)==0){
Serial.print("(cancelled)\n\n"); LOG0("(cancelled)\n\n");
return; return;
} }
if(strlen(textPwd)==33){ 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; return;
} }
Serial.print(mask(textPwd,2)); LOG0("%s\n",mask(textPwd,2).c_str());
Serial.print("\n");
spanOTA.setPassword(textPwd); spanOTA.setPassword(textPwd);
nvs_set_str(otaNVS,"OTADATA",spanOTA.otaPwd); // update data nvs_set_str(otaNVS,"OTADATA",spanOTA.otaPwd); // update data
nvs_commit(otaNVS); 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) if(!spanOTA.enabled)
Serial.print("... Note: OTA has not been enabled in this sketch.\n"); LOG0("... Note: OTA has not been enabled in this sketch.\n");
Serial.print("\n"); LOG0("\n");
} }
break; break;
case 'S': { case 'S': {
char buf[128];
char setupCode[10]; char setupCode[10];
struct { // temporary structure to hold SRP verification code and salt stored in NVS 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); sscanf(c+1," %9[0-9]",setupCode);
if(strlen(setupCode)!=8){ 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 } else
if(!network.allowedCode(setupCode)){ 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 { } else {
sprintf(buf,"\n\nGenerating SRP verification data for new Setup Code: %.3s-%.2s-%.3s ... ",setupCode,setupCode+3,setupCode+5); LOG0("\nGenerating SRP verification data for new Setup Code: %.3s-%.2s-%.3s ... ",setupCode,setupCode+3,setupCode+5);
Serial.print(buf);
HAPClient::srp.createVerifyCode(setupCode,verifyData.verifyCode,verifyData.salt); // create verification code from default Setup Code and random salt 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_set_blob(HAPClient::srpNVS,"VERIFYDATA",&verifyData,sizeof(verifyData)); // update data
nvs_commit(HAPClient::srpNVS); // commit to NVS nvs_commit(HAPClient::srpNVS); // commit to NVS
Serial.print("New Code Saved!\n"); LOG0("New Code Saved!\n");
LOG0("Setup Payload for Optional QR Code: %s\n\n",qrCode.get(atoi(setupCode),qrID,atoi(category)));
Serial.print("Setup Payload for Optional QR Code: ");
Serial.print(qrCode.get(atoi(setupCode),qrID,atoi(category)));
Serial.print("\n\n");
} }
} }
break; break;
@ -695,7 +685,7 @@ void Span::processSerialCommand(const char *c){
HAPClient::removeControllers(); // clear all Controller data HAPClient::removeControllers(); // clear all Controller data
nvs_set_blob(HAPClient::hapNVS,"CONTROLLERS",HAPClient::controllers,sizeof(HAPClient::controllers)); // update data nvs_set_blob(HAPClient::hapNVS,"CONTROLLERS",HAPClient::controllers,sizeof(HAPClient::controllers)); // update data
nvs_commit(HAPClient::hapNVS); // commit to NVS 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;i<maxConnections;i++){ // loop over all connection slots for(int i=0;i<maxConnections;i++){ // loop over all connection slots
if(hap[i]->client){ // if slot is connected if(hap[i]->client){ // 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) mdns_service_txt_item_set("_hap","_tcp","sf","1"); // set Status Flag = 1 (Table 6-8)
if(homeSpan.pairCallback) if(homeSpan.pairCallback)
@ -719,7 +709,7 @@ void Span::processSerialCommand(const char *c){
case 'W': { case 'W': {
if(strlen(network.wifiData.ssid)>0){ 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(); hapServer->end();
MDNS.end(); MDNS.end();
WiFi.disconnect(); WiFi.disconnect();
@ -728,7 +718,7 @@ void Span::processSerialCommand(const char *c){
network.serialConfigure(); network.serialConfigure();
nvs_set_blob(wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data nvs_set_blob(wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data
nvs_commit(wifiNVS); // commit to NVS nvs_commit(wifiNVS); // commit to NVS
Serial.print("\n*** WiFi Credentials SAVED! Restarting ***\n\n"); LOG0("\n*** WiFi Credentials SAVED! Restarting ***\n\n");
reboot(); reboot();
} }
break; break;
@ -736,7 +726,7 @@ void Span::processSerialCommand(const char *c){
case 'A': { case 'A': {
if(strlen(network.wifiData.ssid)>0){ 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(); hapServer->end();
MDNS.end(); MDNS.end();
WiFi.disconnect(); WiFi.disconnect();
@ -750,16 +740,16 @@ void Span::processSerialCommand(const char *c){
network.apConfigure(); network.apConfigure();
nvs_set_blob(wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data nvs_set_blob(wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data
nvs_commit(wifiNVS); // commit to NVS nvs_commit(wifiNVS); // commit to NVS
Serial.print("\n*** Credentials saved!\n"); LOG0("\n*** Credentials saved!\n");
if(strlen(network.setupCode)){ if(strlen(network.setupCode)){
char s[10]; char s[10];
sprintf(s,"S%s",network.setupCode); sprintf(s,"S%s",network.setupCode);
processSerialCommand(s); processSerialCommand(s);
} else { } 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) STATUS_UPDATE(start(LED_ALERT),HS_AP_TERMINATED)
reboot(); reboot();
} }
@ -770,7 +760,7 @@ void Span::processSerialCommand(const char *c){
nvs_erase_all(wifiNVS); nvs_erase_all(wifiNVS);
nvs_commit(wifiNVS); nvs_commit(wifiNVS);
WiFi.begin("none"); WiFi.begin("none");
Serial.print("\n*** WiFi Credentials ERASED! Restarting...\n\n"); LOG0("\n*** WiFi Credentials ERASED! Restarting...\n\n");
reboot(); reboot();
} }
break; break;
@ -779,7 +769,7 @@ void Span::processSerialCommand(const char *c){
nvs_erase_all(charNVS); nvs_erase_all(charNVS);
nvs_commit(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; break;
@ -787,7 +777,7 @@ void Span::processSerialCommand(const char *c){
nvs_erase_all(HAPClient::hapNVS); nvs_erase_all(HAPClient::hapNVS);
nvs_commit(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(); reboot();
} }
break; break;
@ -809,7 +799,7 @@ void Span::processSerialCommand(const char *c){
nvs_erase_all(otaNVS); nvs_erase_all(otaNVS);
nvs_commit(otaNVS); nvs_commit(otaNVS);
WiFi.begin("none"); WiFi.begin("none");
Serial.print("\n*** FACTORY RESET! Restarting...\n\n"); LOG0("\n*** FACTORY RESET! Restarting...\n\n");
reboot(); reboot();
} }
break; break;
@ -817,7 +807,7 @@ void Span::processSerialCommand(const char *c){
case 'E': { case 'E': {
nvs_flash_erase(); nvs_flash_erase();
Serial.print("\n*** ALL DATA ERASED! Restarting...\n\n"); LOG0("\n*** ALL DATA ERASED! Restarting...\n\n");
reboot(); reboot();
} }
break; break;
@ -832,22 +822,20 @@ void Span::processSerialCommand(const char *c){
if(level>2) if(level>2)
level=2; level=2;
Serial.print("\n*** Log Level set to "); LOG0("\n*** Log Level set to %d\n\n",level);
Serial.print(level);
Serial.print("\n\n");
delay(1000); delay(1000);
setLogLevel(level); setLogLevel(level);
} }
break; break;
case 'm': { 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; break;
case 'i':{ case 'i':{
Serial.print("\n*** HomeSpan Info ***\n\n"); LOG0("\n*** HomeSpan Info ***\n\n");
int nErrors=0; int nErrors=0;
int nWarnings=0; int nWarnings=0;
@ -856,25 +844,24 @@ void Span::processSerialCommand(const char *c){
char pNames[][7]={"PR","PW","EV","AA","TW","HD","WR"}; char pNames[][7]={"PR","PW","EV","AA","TW","HD","WR"};
for(auto acc=Accessories.begin(); acc!=Accessories.end(); acc++){ 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; boolean foundInfo=false;
if(acc==Accessories.begin() && (*acc)->aid!=1) 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()) 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); aidValues.insert((*acc)->aid);
for(auto svc=(*acc)->Services.begin(); svc!=(*acc)->Services.end(); svc++){ 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); LOG0(" \u279f Service %s: IID=%d, %sUUID=\"%s\"\n",(*svc)->hapName,(*svc)->iid,(*svc)->isCustom?"Custom-":"",(*svc)->type);
Serial.printf("\n");
if(!strcmp((*svc)->type,"3E")){ if(!strcmp((*svc)->type,"3E")){
foundInfo=true; foundInfo=true;
if((*svc)->iid!=1) 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... 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 isBridge=false; // ...this is not a bridge device
@ -882,45 +869,45 @@ void Span::processSerialCommand(const char *c){
unordered_set<HapChar *> hapChar; unordered_set<HapChar *> hapChar;
for(auto chr=(*svc)->Characteristics.begin(); chr!=(*svc)->Characteristics.end(); chr++){ 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-":""); (*chr)->hapName,(*chr)->uvPrint((*chr)->value).c_str(),(*chr)->iid,(*chr)->isCustom?"Custom-":"",(*chr)->type,(*chr)->perms!=(*chr)->hapChar->perms?"Custom-":"");
int foundPerms=0; int foundPerms=0;
for(uint8_t i=0;i<7;i++){ for(uint8_t i=0;i<7;i++){
if((*chr)->perms & (1<<i)) if((*chr)->perms & (1<<i))
Serial.printf("%s%s",(foundPerms++)?"+":"",pNames[i]); LOG0("%s%s",(foundPerms++)?"+":"",pNames[i]);
} }
if((*chr)->format!=FORMAT::STRING && (*chr)->format!=FORMAT::BOOL && (*chr)->format!=FORMAT::DATA){ if((*chr)->format!=FORMAT::STRING && (*chr)->format!=FORMAT::BOOL && (*chr)->format!=FORMAT::DATA){
if((*chr)->validValues) if((*chr)->validValues)
Serial.printf(", Valid Values=%s",(*chr)->validValues); LOG0(", Valid Values=%s",(*chr)->validValues);
else if((*chr)->uvGet<double>((*chr)->stepValue)>0) else if((*chr)->uvGet<double>((*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 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) if((*chr)->nvsKey)
Serial.printf(" (nvs)"); LOG0(" (nvs)");
Serial.printf("\n"); LOG0("\n");
if(!(*chr)->isCustom && !(*svc)->isCustom && (*svc)->req.find((*chr)->hapChar)==(*svc)->req.end() && (*svc)->opt.find((*chr)->hapChar)==(*svc)->opt.end()) 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 else
if(invalidUUID((*chr)->type,(*chr)->isCustom)) 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 else
if(hapChar.find((*chr)->hapChar)!=hapChar.end()) 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) 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) 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<double>((*chr)->value) < (*chr)->uvGet<double>((*chr)->minValue) || (*chr)->uvGet<double>((*chr)->value) > (*chr)->uvGet<double>((*chr)->maxValue))) if((*chr)->format!=STRING && ((*chr)->uvGet<double>((*chr)->value) < (*chr)->uvGet<double>((*chr)->minValue) || (*chr)->uvGet<double>((*chr)->value) > (*chr)->uvGet<double>((*chr)->maxValue)))
Serial.printf(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet<double>((*chr)->value),(*chr)->uvGet<double>((*chr)->minValue),(*chr)->uvGet<double>((*chr)->maxValue)); LOG0(" *** WARNING #%d! Value of %g is out of range [%g,%g] ***\n",++nWarnings,(*chr)->uvGet<double>((*chr)->value),(*chr)->uvGet<double>((*chr)->minValue),(*chr)->uvGet<double>((*chr)->maxValue));
hapChar.insert((*chr)->hapChar); 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++){ for(auto req=(*svc)->req.begin(); req!=(*svc)->req.end(); req++){
if(hapChar.find(*req)==hapChar.end()) 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++){ for(auto button=PushButtons.begin(); button!=PushButtons.end(); button++){
if((*button)->service==(*svc)){ if((*button)->service==(*svc)){
if((*button)->buttonType==SpanButton::HS_BUTTON) 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 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) 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) 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 #if SOC_TOUCH_SENSOR_NUM > 0
else if((*button)->triggerType==PushButton::TRIGGER_ON_TOUCH) else if((*button)->triggerType==PushButton::TRIGGER_ON_TOUCH)
Serial.printf("TRIGGER_ON_TOUCH\n"); LOG0("TRIGGER_ON_TOUCH\n");
#endif #endif
else else
Serial.printf("USER-DEFINED\n"); LOG0("USER-DEFINED\n");
if((void(*)(int,int))((*svc)->*(&SpanService::button))==(void(*)(int,int))(&SpanService::button)) 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 } // Services
if(!foundInfo) if(!foundInfo)
Serial.printf(" *** ERROR #%d! Required 'AccessoryInformation' Service not found ***\n",++nErrors); LOG0(" *** ERROR #%d! Required 'AccessoryInformation' Service not found ***\n",++nErrors);
} // Accessories } // Accessories
Serial.printf("\nConfigured as Bridge: %s\n",isBridge?"YES":"NO"); LOG0("\nConfigured as Bridge: %s\n",isBridge?"YES":"NO");
if(hapConfig.configNumber>0) if(hapConfig.configNumber>0)
Serial.printf("Configuration Number: %d\n",hapConfig.configNumber); LOG0("Configuration Number: %d\n",hapConfig.configNumber);
Serial.printf("\nDatabase Validation: Warnings=%d, Errors=%d\n\n",nWarnings,nErrors); LOG0("\nDatabase Validation: Warnings=%d, Errors=%d\n\n",nWarnings,nErrors);
char d[]="------------------------------"; char d[]="------------------------------";
Serial.printf("%-30s %8s %10s %s %s %s %s %s\n","Service","UUID","AID","IID","Update","Loop","Button","Linked Services"); LOG0("%-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 %.3s %.6s %.4s %.6s %.15s\n",d,d,d,d,d,d,d,d);
for(int i=0;i<Accessories.size();i++){ // identify all services with over-ridden loop() methods for(int i=0;i<Accessories.size();i++){ // identify all services with over-ridden loop() methods
for(int j=0;j<Accessories[i]->Services.size();j++){ for(int j=0;j<Accessories[i]->Services.size();j++){
SpanService *s=Accessories[i]->Services[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::update))!=(void(*)())(&SpanService::update)?"YES":"NO",
(void(*)())(s->*(&SpanService::loop))!=(void(*)())(&SpanService::loop)?"YES":"NO", (void(*)())(s->*(&SpanService::loop))!=(void(*)())(&SpanService::loop)?"YES":"NO",
(void(*)(int,boolean))(s->*(&SpanService::button))!=(void(*)(int,boolean))(&SpanService::button)?"YES":"NO" (void(*)(int,boolean))(s->*(&SpanService::button))!=(void(*)(int,boolean))(&SpanService::button)?"YES":"NO"
); );
if(s->linkedServices.empty()) if(s->linkedServices.empty())
Serial.print("-"); LOG0("-");
for(int k=0;k<s->linkedServices.size();k++){ for(int k=0;k<s->linkedServices.size();k++){
Serial.print(s->linkedServices[k]->iid); LOG0("%d",s->linkedServices[k]->iid);
if(k<s->linkedServices.size()-1) if(k<s->linkedServices.size()-1)
Serial.print(","); LOG0(",");
} }
Serial.print("\n"); LOG0("\n");
} }
} }
@ -994,75 +981,75 @@ void Span::processSerialCommand(const char *c){
uint8_t channel; uint8_t channel;
wifi_second_chan_t channel2; wifi_second_chan_t channel2;
esp_wifi_get_channel(&channel,&channel2); esp_wifi_get_channel(&channel,&channel2);
Serial.printf("\nFound %d SpanPoint Links:\n\n",SpanPoint::SpanPoints.size()); LOG0("\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"); LOG0("%-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("%.17s %.18s %.7s %.7s %.7s\n",d,d,d,d,d);
for(auto it=SpanPoint::SpanPoints.begin();it!=SpanPoint::SpanPoints.end();it++) 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)->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)); (*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; break;
case 'P': { 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; size_t olen;
TempBuffer<char> tBuf(256); TempBuffer<char> tBuf(256);
mbedtls_base64_encode((uint8_t *)tBuf.buf,256,&olen,(uint8_t *)&HAPClient::accessory,sizeof(struct Accessory)); 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<HAPClient::MAX_CONTROLLERS;i++){ for(int i=0;i<HAPClient::MAX_CONTROLLERS;i++){
if(HAPClient::controllers[i].allocated){ if(HAPClient::controllers[i].allocated){
mbedtls_base64_encode((uint8_t *)tBuf.buf,256,&olen,(uint8_t *)(HAPClient::controllers+i),sizeof(struct Controller)); mbedtls_base64_encode((uint8_t *)tBuf.buf,256,&olen,(uint8_t *)(HAPClient::controllers+i),sizeof(struct Controller));
Serial.printf("Controller data: %s\n",tBuf.buf); LOG0("Controller data: %s\n",tBuf.buf);
} }
} }
Serial.printf("\n*** End Pairing Data\n\n"); LOG0("\n*** End Pairing Data\n\n");
} }
break; break;
case 'C': { case 'C': {
Serial.printf("\n*** Clone Pairing Data from another Device\n\n"); LOG0("\n*** Clone Pairing Data from another Device\n\n");
TempBuffer<char> tBuf(200); TempBuffer<char> tBuf(200);
size_t olen; size_t olen;
tBuf.buf[0]='\0'; tBuf.buf[0]='\0';
Serial.print(">>> Accessory data: "); LOG0(">>> Accessory data: ");
readSerial(tBuf.buf,199); readSerial(tBuf.buf,199);
if(strlen(tBuf.buf)==0){ if(strlen(tBuf.buf)==0){
Serial.printf("(cancelled)\n\n"); LOG0("(cancelled)\n\n");
return; return;
} }
mbedtls_base64_decode((uint8_t *)&HAPClient::accessory,sizeof(struct Accessory),&olen,(uint8_t *)tBuf.buf,strlen(tBuf.buf)); mbedtls_base64_decode((uint8_t *)&HAPClient::accessory,sizeof(struct Accessory),&olen,(uint8_t *)tBuf.buf,strlen(tBuf.buf));
if(olen!=sizeof(struct Accessory)){ 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(); reboot();
} else { } else {
HAPClient::charPrintRow(HAPClient::accessory.ID,17); HAPClient::charPrintRow(HAPClient::accessory.ID,17);
Serial.printf("\n"); LOG0("\n");
} }
for(int i=0;i<HAPClient::MAX_CONTROLLERS;i++){ for(int i=0;i<HAPClient::MAX_CONTROLLERS;i++){
tBuf.buf[0]='\0'; tBuf.buf[0]='\0';
Serial.print(">>> Controller data: "); LOG0(">>> Controller data: ");
readSerial(tBuf.buf,199); readSerial(tBuf.buf,199);
if(strlen(tBuf.buf)==0){ if(strlen(tBuf.buf)==0){
Serial.printf("(done)\n"); LOG0("(done)\n");
while(i<HAPClient::MAX_CONTROLLERS) // clear data from remaining controller slots while(i<HAPClient::MAX_CONTROLLERS) // clear data from remaining controller slots
HAPClient::controllers[i++].allocated=false; HAPClient::controllers[i++].allocated=false;
} else { } else {
mbedtls_base64_decode((uint8_t *)(HAPClient::controllers+i),sizeof(struct Controller),&olen,(uint8_t *)tBuf.buf,strlen(tBuf.buf)); mbedtls_base64_decode((uint8_t *)(HAPClient::controllers+i),sizeof(struct Controller),&olen,(uint8_t *)tBuf.buf,strlen(tBuf.buf));
if(olen!=sizeof(struct Controller)){ if(olen!=sizeof(struct Controller)){
Serial.printf("\n*** Error in size of Controller data - cloning cancelled. Restarting...\n\n"); LOG0("\n*** Error in size of Controller data - cloning cancelled. Restarting...\n\n");
reboot(); reboot();
} else { } else {
HAPClient::charPrintRow(HAPClient::controllers[i].ID,36); HAPClient::charPrintRow(HAPClient::controllers[i].ID,36);
Serial.printf("\n"); LOG0("\n");
} }
} }
} }
@ -1070,61 +1057,61 @@ void Span::processSerialCommand(const char *c){
char qSave[2]; char qSave[2];
while(1){ while(1){
qSave[0]='-'; qSave[0]='-';
Serial.printf("Save Cloned Pairing Data (y/n): "); LOG0("Save Cloned Pairing Data (y/n): ");
readSerial(qSave,1); readSerial(qSave,1);
if(qSave[0]=='y'){ if(qSave[0]=='y'){
Serial.printf("(yes)\nData saved! Rebooting..."); LOG0("(yes)\nData saved! Rebooting...");
nvs_set_blob(HAPClient::hapNVS,"ACCESSORY",&HAPClient::accessory,sizeof(HAPClient::accessory)); // update data nvs_set_blob(HAPClient::hapNVS,"ACCESSORY",&HAPClient::accessory,sizeof(HAPClient::accessory)); // update data
nvs_set_blob(HAPClient::hapNVS,"CONTROLLERS",HAPClient::controllers,sizeof(HAPClient::controllers)); nvs_set_blob(HAPClient::hapNVS,"CONTROLLERS",HAPClient::controllers,sizeof(HAPClient::controllers));
nvs_commit(HAPClient::hapNVS); // commit to NVS nvs_commit(HAPClient::hapNVS); // commit to NVS
reboot(); reboot();
} else } else
if(qSave[0]=='n'){ if(qSave[0]=='n'){
Serial.printf("(no)\nProcess Cancelled! Rebooting..."); LOG0("(no)\nProcess Cancelled! Rebooting...");
reboot(); reboot();
} }
Serial.printf("\n"); LOG0("\n");
} }
} }
break; break;
case '?': { case '?': {
Serial.print("\n*** HomeSpan Commands ***\n\n"); LOG0("\n*** HomeSpan Commands ***\n\n");
Serial.print(" s - print connection status\n"); LOG0(" s - print connection status\n");
Serial.print(" i - print summary information about the HAP Database\n"); LOG0(" i - print summary information about the HAP Database\n");
Serial.print(" d - print the full HAP Accessory Attributes Database in JSON format\n"); LOG0(" d - print the full HAP Accessory Attributes Database in JSON format\n");
Serial.print(" m - print free heap memory\n"); LOG0(" m - print free heap memory\n");
Serial.print("\n"); LOG0("\n");
Serial.print(" W - configure WiFi Credentials and restart\n"); LOG0(" W - configure WiFi Credentials and restart\n");
Serial.print(" X - delete WiFi Credentials and restart\n"); LOG0(" X - delete WiFi Credentials and restart\n");
Serial.print(" S <code> - change the HomeKit Pairing Setup Code to <code>\n"); LOG0(" S <code> - change the HomeKit Pairing Setup Code to <code>\n");
Serial.print(" Q <id> - change the HomeKit Setup ID for QR Codes to <id>\n"); LOG0(" Q <id> - change the HomeKit Setup ID for QR Codes to <id>\n");
Serial.print(" O - change the OTA password\n"); LOG0(" O - change the OTA password\n");
Serial.print(" A - start the HomeSpan Setup Access Point\n"); LOG0(" A - start the HomeSpan Setup Access Point\n");
Serial.print("\n"); LOG0("\n");
Serial.print(" V - delete value settings for all saved Characteristics\n"); LOG0(" V - delete value settings for all saved Characteristics\n");
Serial.print(" U - unpair device by deleting all Controller data\n"); LOG0(" 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"); LOG0(" H - delete HomeKit Device ID as well as all Controller data and restart\n");
Serial.print("\n"); LOG0("\n");
Serial.print(" P - output Pairing Data that can be saved offline to clone a new device\n"); LOG0(" 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"); LOG0(" C - clone Pairing Data previously saved offline from another device\n");
Serial.print("\n"); LOG0("\n");
Serial.print(" R - restart device\n"); LOG0(" R - restart device\n");
Serial.print(" F - factory reset and restart\n"); LOG0(" F - factory reset and restart\n");
Serial.print(" E - erase ALL stored data and restart\n"); LOG0(" E - erase ALL stored data and restart\n");
Serial.print("\n"); LOG0("\n");
Serial.print(" L <level> - change the Log Level setting to <level>\n"); LOG0(" L <level> - change the Log Level setting to <level>\n");
Serial.print("\n"); LOG0("\n");
for(auto uCom=homeSpan.UserCommands.begin(); uCom!=homeSpan.UserCommands.end(); uCom++) // loop over all UserCommands using an iterator 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()) if(!homeSpan.UserCommands.empty())
Serial.print("\n"); LOG0("\n");
Serial.print(" ? - print this list of commands\n\n"); LOG0(" ? - print this list of commands\n\n");
Serial.print("*** End Commands ***\n\n"); LOG0("*** End Commands ***\n\n");
} }
break; break;
@ -1138,17 +1125,13 @@ void Span::processSerialCommand(const char *c){
else else
uCom->second->userFunction2(c+1,uCom->second->userArg); uCom->second->userFunction2(c+1,uCom->second->userArg);
} else { } else {
Serial.print("*** Undefined user command: '"); LOG0("*** Undefined user command: '%s'. Type '?' for list of commands.\n",c);
Serial.print(c);
Serial.print("'. Type '?' for list of commands.\n");
} }
} }
break; break;
default: default:
Serial.print("*** Unknown command: '"); LOG0("*** Unknown command: '%s'. Type '?' for list of commands.\n",c);
Serial.print(c);
Serial.print("'. Type '?' for list of commands.\n");
break; break;
} // switch } // switch
@ -1244,37 +1227,35 @@ void Span::prettyPrint(char *buf, int nsp){
case '{': case '{':
case '[': case '[':
Serial.print(buf[i]); LOG0("%c\n",buf[i]);
Serial.print("\n");
indent+=nsp; indent+=nsp;
for(int j=0;j<indent;j++) for(int j=0;j<indent;j++)
Serial.print(" "); LOG0(" ");
break; break;
case '}': case '}':
case ']': case ']':
Serial.print("\n"); LOG0("\n");
indent-=nsp; indent-=nsp;
for(int j=0;j<indent;j++) for(int j=0;j<indent;j++)
Serial.print(" "); LOG0(" ");
Serial.print(buf[i]); LOG0("%c",buf[i]);
break; break;
case ',': case ',':
Serial.print(buf[i]); LOG0("%c\n",buf[i]);
Serial.print("\n");
for(int j=0;j<indent;j++) for(int j=0;j<indent;j++)
Serial.print(" "); LOG0(" ");
break; break;
default: default:
Serial.print(buf[i]); LOG0("%c",buf[i]);
} // switch } // switch
} // loop over all characters } // loop over all characters
Serial.print("\n"); LOG0("\n");
} // prettyPrint }
/////////////////////////// ///////////////////////////
@ -1350,7 +1331,7 @@ int Span::updateCharacteristics(char *buf, SpanBuf *pObj){
if(!cFound){ // first token found if(!cFound){ // first token found
if(strcmp(t2,"characteristics")){ if(strcmp(t2,"characteristics")){
Serial.print("\n*** ERROR: Problems parsing JSON - initial \"characteristics\" tag not found\n\n"); LOG0("\n*** ERROR: Problems parsing JSON - initial \"characteristics\" tag not found\n\n");
return(0); return(0);
} }
cFound=1; cFound=1;
@ -1378,17 +1359,15 @@ int Span::updateCharacteristics(char *buf, SpanBuf *pObj){
if(!strcmp(t2,"pid") && (t3=strtok_r(t1,"}[]:, \"\t\n\r",&p2))){ if(!strcmp(t2,"pid") && (t3=strtok_r(t1,"}[]:, \"\t\n\r",&p2))){
uint64_t pid=strtoull(t3,NULL,0); uint64_t pid=strtoull(t3,NULL,0);
if(!TimedWrites.count(pid)){ if(!TimedWrites.count(pid)){
Serial.print("\n*** ERROR: Timed Write PID not found\n\n"); LOG0("\n*** ERROR: Timed Write PID not found\n\n");
twFail=true; twFail=true;
} else } else
if(millis()>TimedWrites[pid]){ if(millis()>TimedWrites[pid]){
Serial.print("\n*** ERROR: Timed Write Expired\n\n"); LOG0("\n*** ERROR: Timed Write Expired\n\n");
twFail=true; twFail=true;
} }
} else { } else {
Serial.print("\n*** ERROR: Problems parsing JSON characteristics object - unexpected property \""); LOG0("\n*** ERROR: Problems parsing JSON characteristics object - unexpected property \"%s\"\n\n",t2);
Serial.print(t2);
Serial.print("\"\n\n");
return(0); return(0);
} }
} // parse property tokens } // 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 if(okay==7 || okay==11 || okay==15){ // all required properties found
nObj++; // increment number of characteristic objects found nObj++; // increment number of characteristic objects found
} else { } 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); return(0);
} }
} }
@ -1626,9 +1605,7 @@ SpanAccessory::SpanAccessory(uint32_t aid){
if(!homeSpan.Accessories.empty()){ if(!homeSpan.Accessories.empty()){
if(homeSpan.Accessories.size()==HAPClient::MAX_ACCESSORIES){ if(homeSpan.Accessories.size()==HAPClient::MAX_ACCESSORIES){
Serial.print("\n\n*** FATAL ERROR: Can't create more than "); LOG0("\n\n*** FATAL ERROR: Can't create more than %d Accessories. Program Halting.\n\n",HAPClient::MAX_ACCESSORIES);
Serial.print(HAPClient::MAX_ACCESSORIES);
Serial.print(" Accessories. Program Halting.\n\n");
while(1); while(1);
} }
@ -1685,8 +1662,8 @@ int SpanAccessory::sprintfAttributes(char *cBuf, int flags){
SpanService::SpanService(const char *type, const char *hapName, boolean isCustom){ SpanService::SpanService(const char *type, const char *hapName, boolean isCustom){
if(homeSpan.Accessories.empty()){ if(homeSpan.Accessories.empty()){
Serial.printf("\nFATAL ERROR! Can't create new Service '%s' without a defined Accessory ***\n",hapName); LOG0("\nFATAL ERROR! Can't create new Service '%s' without a defined Accessory ***\n",hapName);
Serial.printf("\n=== PROGRAM HALTED ==="); LOG0("\n=== PROGRAM HALTED ===");
while(1); while(1);
} }
@ -1803,8 +1780,8 @@ SpanCharacteristic::SpanCharacteristic(HapChar *hapChar, boolean isCustom){
this->hapChar=hapChar; this->hapChar=hapChar;
if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){ 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); LOG0("\nFATAL ERROR! Can't create new Characteristic '%s' without a defined Service ***\n",hapName);
Serial.printf("\n=== PROGRAM HALTED ==="); LOG0("\n=== PROGRAM HALTED ===");
while(1); while(1);
} }
@ -2068,8 +2045,8 @@ SpanCharacteristic *SpanCharacteristic::setValidValues(int n, ...){
SpanRange::SpanRange(int min, int max, int step){ SpanRange::SpanRange(int min, int max, int step){
if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty() || homeSpan.Accessories.back()->Services.back()->Characteristics.empty() ){ 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); LOG0("\nFATAL ERROR! Can't create new SpanRange(%d,%d,%d) without a defined Characteristic ***\n",min,max,step);
Serial.printf("\n=== PROGRAM HALTED ==="); LOG0("\n=== PROGRAM HALTED ===");
while(1); while(1);
} else { } else {
homeSpan.Accessories.back()->Services.back()->Characteristics.back()->setRange(min,max,step); 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(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){
if(buttonType==HS_BUTTON) 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 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); while(1);
} }
@ -2173,9 +2150,9 @@ void SpanWebLog::vLog(boolean sysMsg, const char *fmt, va_list ap){
vasprintf(&buf,fmt,ap); vasprintf(&buf,fmt,ap);
if(sysMsg) if(sysMsg)
Serial.printf("%s\n",buf); LOG0("%s\n",buf);
else if(homeSpan.logLevel>0) else if(homeSpan.logLevel>0)
Serial.printf("WEBLOG: %s\n",buf); LOG0("WEBLOG: %s\n",buf);
if(maxEntries>0){ if(maxEntries>0){
int index=nEntries%maxEntries; 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){ int SpanOTA::init(boolean _auth, boolean _safeLoad, const char *pwd){
if(esp_ota_get_running_partition()==esp_ota_get_next_update_partition(NULL)){ 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); return(-1);
} }
@ -2219,7 +2196,7 @@ int SpanOTA::init(boolean _auth, boolean _safeLoad, const char *pwd){
int SpanOTA::setPassword(const char *pwd){ int SpanOTA::setPassword(const char *pwd){
if(strlen(pwd)<1 || strlen(pwd)>32){ 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); return(-1);
} }
@ -2234,7 +2211,7 @@ int SpanOTA::setPassword(const char *pwd){
/////////////////////////////// ///////////////////////////////
void SpanOTA::start(){ 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); esp_ota_get_running_partition()->label,esp_ota_get_next_update_partition(NULL)->label);
otaPercent=0; otaPercent=0;
STATUS_UPDATE(start(LED_OTA_STARTED),HS_OTA_STARTED) STATUS_UPDATE(start(LED_OTA_STARTED),HS_OTA_STARTED)
@ -2245,7 +2222,7 @@ void SpanOTA::start(){
void SpanOTA::end(){ void SpanOTA::end(){
nvs_set_u8(homeSpan.otaNVS,"OTA_REQUIRED",safeLoad); nvs_set_u8(homeSpan.otaNVS,"OTA_REQUIRED",safeLoad);
nvs_commit(homeSpan.otaNVS); nvs_commit(homeSpan.otaNVS);
Serial.printf(" DONE! Rebooting...\n"); LOG0(" DONE! Rebooting...\n");
homeSpan.reboot(); homeSpan.reboot();
} }
@ -2255,13 +2232,13 @@ void SpanOTA::progress(uint32_t progress, uint32_t total){
int percent=progress*100/total; int percent=progress*100/total;
if(percent/10 != otaPercent/10){ if(percent/10 != otaPercent/10){
otaPercent=percent; otaPercent=percent;
Serial.printf("%d%%..",progress*100/total); LOG0("%d%%..",progress*100/total);
} }
if(safeLoad && progress==total){ if(safeLoad && progress==total){
SpanPartition newSpanPartition; 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)); 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)) if(strcmp(newSpanPartition.magicCookie,spanPartition.magicCookie))
Update.abort(); Update.abort();
} }
@ -2270,12 +2247,12 @@ void SpanOTA::progress(uint32_t progress, uint32_t total){
/////////////////////////////// ///////////////////////////////
void SpanOTA::error(ota_error_t err){ void SpanOTA::error(ota_error_t err){
Serial.printf("*** OTA Error[%u]: ", err); LOG0("*** OTA Error[%u]: ", err);
if (err == OTA_AUTH_ERROR) Serial.println("Auth Failed\n"); if (err == OTA_AUTH_ERROR) LOG0("Auth Failed\n\n");
else if (err == OTA_BEGIN_ERROR) Serial.println("Begin Failed\n"); else if (err == OTA_BEGIN_ERROR) LOG0("Begin Failed\n\n");
else if (err == OTA_CONNECT_ERROR) Serial.println("Connect Failed\n"); else if (err == OTA_CONNECT_ERROR) LOG0("Connect Failed\n\n");
else if (err == OTA_RECEIVE_ERROR) Serial.println("Receive Failed\n"); else if (err == OTA_RECEIVE_ERROR) LOG0("Receive Failed\n\n");
else if (err == OTA_END_ERROR) Serial.println("End Failed\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){ 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){ 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); LOG0("\nFATAL ERROR! Can't create new SpanPoint(\"%s\") - Invalid MAC Address ***\n",macAddress);
Serial.printf("\n=== PROGRAM HALTED ==="); LOG0("\n=== PROGRAM HALTED ===");
while(1); while(1);
} }
if(sendSize<0 || sendSize>200 || receiveSize<0 || receiveSize>200 || queueDepth<1 || (sendSize==0 && receiveSize==0)){ 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); LOG0("\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("\n=== PROGRAM HALTED ===");
while(1); while(1);
} }
@ -2380,8 +2357,8 @@ void SpanPoint::setChannelMask(uint16_t mask){
channel=(channelMask & (1<<i))?i:0; channel=(channelMask & (1<<i))?i:0;
if(channel==0){ if(channel==0){
Serial.printf("\nFATAL ERROR! SpanPoint::setChannelMask(0x%04X) - mask must allow for at least one channel ***\n",mask); LOG0("\nFATAL ERROR! SpanPoint::setChannelMask(0x%04X) - mask must allow for at least one channel ***\n",mask);
Serial.printf("\n=== PROGRAM HALTED ==="); LOG0("\n=== PROGRAM HALTED ===");
while(1); while(1);
} }
@ -2467,7 +2444,7 @@ void SpanPoint::dataReceived(const uint8_t *mac, const uint8_t *incomingData, in
return; return;
if(len!=(*it)->receiveSize){ if(len!=(*it)->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; return;
} }

View File

@ -346,7 +346,7 @@ class Span{
void autoPoll(uint32_t stackSize=8192, uint32_t priority=1, uint32_t cpu=0){ // start pollTask() 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); 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 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){ void setString(const char *val){
if((perms & EV) == 0){ 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; return;
} }
@ -669,9 +669,9 @@ class SpanCharacteristic{
return(olen); return(olen);
if(ret==MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) 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) 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); return(olen);
} }
@ -687,9 +687,9 @@ class SpanCharacteristic{
return(olen); return(olen);
if(ret==MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) 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) 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); return(olen);
} }
@ -697,12 +697,12 @@ class SpanCharacteristic{
void setData(uint8_t *data, size_t len){ void setData(uint8_t *data, size_t len){
if((perms & EV) == 0){ 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; return;
} }
if(len<1){ 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; return;
} }
@ -716,12 +716,12 @@ class SpanCharacteristic{
template <typename T> void setVal(T val, boolean notify=true){ template <typename T> void setVal(T val, boolean notify=true){
if((perms & EV) == 0){ 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; return;
} }
if(val < uvGet<T>(minValue) || val > uvGet<T>(maxValue)){ if(val < uvGet<T>(minValue) || val > uvGet<T>(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<double>(minValue),uvGet<double>(maxValue)); hapName,(double)val,uvGet<double>(minValue),uvGet<double>(maxValue));
} }

View File

@ -65,33 +65,26 @@ void Network::serialConfigure(){
wifiData.ssid[0]='\0'; wifiData.ssid[0]='\0';
wifiData.pwd[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 scan(); // scan for networks
for(int i=0;i<numSSID;i++){ for(int i=0;i<numSSID;i++)
Serial.print(" "); LOG0(" %d) %s\n",i+1,ssidList[i]);
Serial.print(i+1);
Serial.print(") ");
Serial.print(ssidList[i]);
Serial.print("\n");
}
while(!strlen(wifiData.ssid)){ while(!strlen(wifiData.ssid)){
Serial.print("\n>>> WiFi SSID: "); LOG0("\n>>> WiFi SSID: ");
readSerial(wifiData.ssid,MAX_SSID); readSerial(wifiData.ssid,MAX_SSID);
if(atoi(wifiData.ssid)>0 && atoi(wifiData.ssid)<=numSSID){ if(atoi(wifiData.ssid)>0 && atoi(wifiData.ssid)<=numSSID){
strcpy(wifiData.ssid,ssidList[atoi(wifiData.ssid)-1]); strcpy(wifiData.ssid,ssidList[atoi(wifiData.ssid)-1]);
} }
Serial.print(wifiData.ssid); LOG0("%s\n",wifiData.ssid);
Serial.print("\n");
} }
while(!strlen(wifiData.pwd)){ while(!strlen(wifiData.pwd)){
Serial.print(">>> WiFi PASS: "); LOG0(">>> WiFi PASS: ");
readSerial(wifiData.pwd,MAX_PWD); readSerial(wifiData.pwd,MAX_PWD);
Serial.print(mask(wifiData.pwd,2)); LOG0("%s\n",mask(wifiData.pwd,2).c_str());
Serial.print("\n");
} }
return; return;
@ -110,25 +103,16 @@ boolean Network::allowedCode(char *s){
void Network::apConfigure(){ void Network::apConfigure(){
Serial.print("*** Starting Access Point: "); LOG0("*** Starting Access Point: %s / %s\n",apSSID,apPassword);
Serial.print(apSSID);
Serial.print(" / ");
Serial.print(apPassword);
Serial.print("\n");
STATUS_UPDATE(start(LED_AP_STARTED),HS_AP_STARTED) 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 scan(); // scan for networks
for(int i=0;i<numSSID;i++){ for(int i=0;i<numSSID;i++)
Serial.print(" "); LOG0(" %d) %s\n",i+1,ssidList[i]);
Serial.print(i+1);
Serial.print(") ");
Serial.print(ssidList[i]);
Serial.print("\n");
}
WiFiServer apServer(80); WiFiServer apServer(80);
client=0; client=0;
@ -148,12 +132,12 @@ void Network::apConfigure(){
alarmTimeOut=millis()+lifetime; // Access Point will shut down when alarmTimeOut is reached alarmTimeOut=millis()+lifetime; // Access Point will shut down when alarmTimeOut is reached
apStatus=0; // status will be "timed out" unless changed apStatus=0; // status will be "timed out" unless changed
Serial.print("\nReady.\n"); LOG0("\nReady.\n");
while(1){ // loop until we get timed out (which will be accelerated if save/cancel selected) while(1){ // loop until we get timed out (which will be accelerated if save/cancel selected)
if(homeSpan.controlButton && homeSpan.controlButton->triggered(9999,3000)){ if(homeSpan.controlButton && homeSpan.controlButton->triggered(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) STATUS_UPDATE(start(LED_ALERT),HS_AP_TERMINATED)
homeSpan.controlButton->wait(); homeSpan.controlButton->wait();
homeSpan.reboot(); homeSpan.reboot();
@ -163,17 +147,14 @@ void Network::apConfigure(){
WiFi.softAPdisconnect(true); // terminate connections and shut down captive access point WiFi.softAPdisconnect(true); // terminate connections and shut down captive access point
delay(100); delay(100);
if(apStatus==1){ 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; return;
} else { } else {
if(apStatus==0){ if(apStatus==0)
Serial.print("\n*** Access Point: Timed Out ("); LOG0("\n*** Access Point: Timed Out (%ld seconds).",lifetime/1000);
Serial.print(lifetime/1000); else
Serial.print(" seconds)."); LOG0("\n*** Access Point: Configuration Cancelled.");
} else { LOG0(" Restarting...\n\n");
Serial.print("\n*** Access Point: Configuration Cancelled.");
}
Serial.print(" Restarting...\n\n");
STATUS_UPDATE(start(LED_ALERT),HS_AP_TERMINATED) STATUS_UPDATE(start(LED_ALERT),HS_AP_TERMINATED)
homeSpan.reboot(); homeSpan.reboot();
} }
@ -202,7 +183,7 @@ void Network::apConfigure(){
if(nBytes>MAX_HTTP){ // exceeded maximum number of bytes allowed if(nBytes>MAX_HTTP){ // exceeded maximum number of bytes allowed
badRequestError(); badRequestError();
Serial.print("\n*** ERROR: Exceeded maximum HTTP message length\n\n"); LOG0("\n*** ERROR: Exceeded maximum HTTP message length\n\n");
continue; continue;
} }
@ -212,7 +193,7 @@ void Network::apConfigure(){
if(!(p=strstr((char *)httpBuf,"\r\n\r\n"))){ if(!(p=strstr((char *)httpBuf,"\r\n\r\n"))){
badRequestError(); 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; continue;
} }
@ -224,7 +205,7 @@ void Network::apConfigure(){
cLen=atoi(p+16); cLen=atoi(p+16);
if(nBytes!=strlen(body)+4+cLen){ if(nBytes!=strlen(body)+4+cLen){
badRequestError(); 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; continue;
} }

View File

@ -273,9 +273,8 @@ void SRP6A::print(mbedtls_mpi *mpi){
mbedtls_mpi_write_string(mpi,16,sBuf,2000,&sLen); 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) 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)
Serial.print(" "); LOG0("%s\n",sBuf);
Serial.println(sBuf);
} }
////////////////////////////////////// //////////////////////////////////////

View File

@ -104,9 +104,9 @@
// Message Log Level Control Macros // // Message Log Level Control Macros //
// 0=Minimal, 1=Informative, 2=All // // 0=Minimal, 1=Informative, 2=All //
#define LOG0(format,...) if(homeSpan.getLogLevel()>=0)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,...) if(homeSpan.getLogLevel()>=1)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__) #define LOG1(format,...) do{ if(homeSpan.getLogLevel()>=1)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__); }while(0)
#define LOG2(format,...) if(homeSpan.getLogLevel()>=2)Serial.print ##__VA_OPT__(f)(format __VA_OPT__(,) __VA_ARGS__) #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__); #define WEBLOG(format,...) homeSpan.addWebLog(false, format __VA_OPT__(,) __VA_ARGS__);