Added code to output configuration log and error messages

Config Log is output if logLevel>1 OR there is a fatal error in configuration
This commit is contained in:
Gregg 2020-10-03 22:21:38 -05:00
parent 1d6f07a400
commit db620e497e
3 changed files with 31 additions and 15 deletions

View File

@ -79,6 +79,16 @@ void Span::poll() {
if(!isInitialized){
if(logLevel>1 || isFatalError){
Serial.print(configLog);
Serial.print("\n*** End Config Log ***\n");
}
if(isFatalError){
Serial.print("\n*** PROGRAM HALTED DUE TO FATAL ERRORS IN CONFIGURATION! ***\n\n");
while(1);
}
Serial.print("\n");
nvs_flash_init(); // initialize non-volatile-storage partition in flash
@ -919,6 +929,8 @@ SpanAccessory::SpanAccessory(){
homeSpan.Accessories.push_back(this);
aid=homeSpan.Accessories.size();
homeSpan.configLog+="+Accessory " + String(aid) + "\n";
}
///////////////////////////////
@ -948,16 +960,17 @@ SpanService::SpanService(const char *type, const char *hapName){
this->type=type;
this->hapName=hapName;
homeSpan.configLog+="-->Service " + String(hapName);
if(homeSpan.Accessories.empty()){
Serial.print("*** FATAL ERROR: Can't create new Service '");
Serial.print(hapName);
Serial.print("' without a defined Accessory. Program halted!\n\n");
while(1);
homeSpan.configLog+=" *** ERROR! Missing Accessory! ***\n";
homeSpan.isFatalError=true;
return;
}
homeSpan.configLog+="\n";
homeSpan.Accessories.back()->Services.push_back(this);
iid=++(homeSpan.Accessories.back()->iidCount);
}
///////////////////////////////
@ -1009,20 +1022,21 @@ SpanCharacteristic::SpanCharacteristic(char *type, uint8_t perms, char *hapName)
this->perms=perms;
this->hapName=hapName;
homeSpan.configLog+="---->Characteristic " + String(hapName);
if(homeSpan.Accessories.empty() || homeSpan.Accessories.back()->Services.empty()){
Serial.print("*** FATAL ERROR: Can't create new Characteristic '");
Serial.print(hapName);
Serial.print("' without a defined Service. Program halted!\n\n");
while(1);
homeSpan.configLog+=" *** ERROR! Missing Service! ***\n";
homeSpan.isFatalError=true;
return;
}
homeSpan.configLog+="\n";
homeSpan.Accessories.back()->Services.back()->Characteristics.push_back(this);
iid=++(homeSpan.Accessories.back()->iidCount);
service=homeSpan.Accessories.back()->Services.back();
aid=homeSpan.Accessories.back()->aid;
ev=(boolean *)calloc(homeSpan.maxConnections,sizeof(boolean));
}
///////////////////////////////

View File

@ -53,6 +53,8 @@ struct Span{
char category[3]=""; // category ID of primary accessory - broadcast as Bonjour field "ci" (HAP Section 13)
unsigned long snapTime; // current time (in millis) snapped before entering Service loops() or updates()
boolean isInitialized=false; // flag indicating HomeSpan has been initialized
boolean isFatalError=false; // flag indicating a fatal error in user-defined configuration
String configLog="*** Config Log ***\n\n"; // log of configuration process, including any errors
char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing
uint8_t statusPin=DEFAULT_STATUS_PIN; // pin for status LED

View File

@ -8,12 +8,12 @@ void setup() {
Serial.begin(115200);
homeSpan.setLogLevel(2);
homeSpan.begin(Category::Lighting,"HomeSpan Benchmark");
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
new Characteristic::Model("HSL Test"); // Model of the Accessory (arbitrary text string, and can be the same for every Accessory)
new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, which has 6 required Characteristics
new Characteristic::Name("HomeSpan Test"); // Name of the Accessory, which shows up on the HomeKit "tiles", and should be unique across Accessories
new Characteristic::Manufacturer("HomeSpan"); // Manufacturer of the Accessory (arbitrary text string, and can be the same for every Accessory)