diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 1de042d..0e34068 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -103,6 +103,10 @@ void Span::poll() { HAPClient::init(); // read NVS and load HAP settings initWifi(); // initialize WiFi + if(!foundWifiCredentials){ + Serial.print("WIFI CREDENTIALS DATA NOT FOUND -- PLEASE CONFIGURE BY TYPING 'W ' OR PRESS CONTROL BUTTON FOR 3 SECONDS TO START ACCESS POINT.\n\n"); + statusLED.start(LED_WIFI_NEEDED); + } else if(!HAPClient::nAdminControllers()){ Serial.print("DEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n"); statusLED.start(LED_PAIRING_NEEDED); @@ -117,7 +121,7 @@ void Span::poll() { isInitialized=true; } - if(WiFi.status()!=WL_CONNECTED){ + if(foundWifiCredentials && WiFi.status()!=WL_CONNECTED){ Serial.print("*** LOST WIFI CONNECTION! ***\n\n"); initWifi(); } @@ -221,6 +225,12 @@ int Span::getFreeSlot(){ void Span::initWifi(){ + size_t len; // not used but required to read blobs from NVS + + if(nvs_get_blob(HAPClient::wifiNVS,"WIFIDATA",NULL,&len)){ // WiFi data not stored + return; + } + char id[18]; // create string version of Accessory ID for MDNS broadcast memcpy(id,HAPClient::accessory.ID,17); // copy ID bytes id[17]='\0'; // add terminating null @@ -231,7 +241,6 @@ void Span::initWifi(){ char hostName[nChars+1]; sprintf(hostName,"%s-%.2s%.2s%.2s%.2s%.2s%.2s",hostNameBase,id,id+3,id+6,id+9,id+12,id+15); - size_t len; // not used but required to read blobs from NVS if(!nvs_get_blob(HAPClient::wifiNVS,"WIFIDATA",NULL,&len)){ // if found WiFi data in NVS nvs_get_blob(HAPClient::wifiNVS,"WIFIDATA",&network.wifiData,&len); // retrieve data diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 4acdf3c..ba0e94c 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -53,6 +53,7 @@ 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 foundWifiCredentials=false; // flag indicating whether or not WiFi credentials data is found in NVS int nFatalErrors=0; // number of fatal errors in user-defined configuration String configLog="\n*** Config Log ***\n\n"; // log of configuration process, including any errors diff --git a/src/Settings.h b/src/Settings.h index b8c1ce8..83dd5d0 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -33,6 +33,7 @@ ///////////////////////////////////////////////////// // STATUS LED SETTINGS // +#define LED_WIFI_NEEDED 500,0.3,1,3000 // slow single-blink #define LED_PAIRING_NEEDED 1000,0.9 // drop-out #define LED_ALERT 100 // rapid flashing #define LED_WIFI_CONNECTING 2000 // slow flashing @@ -40,7 +41,6 @@ #define LED_AP_STARTED 100,0.5,2,500 // rapid double-blink #define LED_AP_CONNECTED 500,0.3,2,1000 // slow double-blink - ///////////////////////////////////////////////////// // Message Log Level Control Macros // // 0=Minimal, 1=Informative, 2=All //