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:
parent
7ecff55f9c
commit
546c5048db
|
|
@ -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]="?";
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue