Fixed bug in initialization logic at beginning of poll()

Full initialization now depends on "isInitialized" flag instead of monitoring Wifi connection, to protect against a loss of WiFi causing a re-initialization, instead of just a wifi reconnect with initWifi() alone.
This commit is contained in:
Gregg 2020-10-03 15:08:44 -05:00
parent 7ecff55f9c
commit 546c5048db
2 changed files with 14 additions and 4 deletions

View File

@ -75,8 +75,11 @@ void Span::poll() {
if(!strlen(category)){
Serial.print("\n** FATAL ERROR: Cannot run homeSpan.poll() without an initial call to homeSpan.begin()!\n** PROGRAM HALTED **\n\n");
while(1);
}
} else if(WiFi.status()!=WL_CONNECTED){
if(!isInitialized){
Serial.print("\n");
nvs_flash_init(); // initialize non-volatile-storage partition in flash
HAPClient::init(); // read NVS and load HAP settings
@ -93,6 +96,12 @@ void Span::poll() {
Serial.print(displayName);
Serial.print(" is READY!\n\n");
isInitialized=true;
}
if(WiFi.status()!=WL_CONNECTED){
Serial.print("*** LOST WIFI CONNECTION! ***\n\n");
initWifi();
}
char cBuf[17]="?";

View File

@ -52,6 +52,7 @@ struct Span{
char *modelName; // model name of this device - broadcast as Bonjour field "md"
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
char *defaultSetupCode=DEFAULT_SETUP_CODE; // Setup Code used for pairing
uint8_t statusPin=DEFAULT_STATUS_PIN; // pin for status LED