Updating WiFi Configuration Logic

Changing code so that it is possible to run HomeSpan without configuring WiFi.  HomeSpan can already run without being paired, but requires WiFi at start-up.  No reason to force WiFi to be used if device has buttons to operate the appliance withouth the need for WiFi or a connection to HomeKit.  Work in progress...
This commit is contained in:
Gregg 2020-10-06 09:09:43 -05:00
parent c30b75280a
commit cf0627e8c9
3 changed files with 13 additions and 3 deletions

View File

@ -103,6 +103,10 @@ void Span::poll() {
HAPClient::init(); // read NVS and load HAP settings HAPClient::init(); // read NVS and load HAP settings
initWifi(); // initialize WiFi initWifi(); // initialize WiFi
if(!foundWifiCredentials){
Serial.print("WIFI CREDENTIALS DATA NOT FOUND -- PLEASE CONFIGURE BY TYPING 'W <RETURN>' OR PRESS CONTROL BUTTON FOR 3 SECONDS TO START ACCESS POINT.\n\n");
statusLED.start(LED_WIFI_NEEDED);
} else
if(!HAPClient::nAdminControllers()){ if(!HAPClient::nAdminControllers()){
Serial.print("DEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n"); Serial.print("DEVICE NOT YET PAIRED -- PLEASE PAIR WITH HOMEKIT APP\n\n");
statusLED.start(LED_PAIRING_NEEDED); statusLED.start(LED_PAIRING_NEEDED);
@ -117,7 +121,7 @@ void Span::poll() {
isInitialized=true; isInitialized=true;
} }
if(WiFi.status()!=WL_CONNECTED){ if(foundWifiCredentials && WiFi.status()!=WL_CONNECTED){
Serial.print("*** LOST WIFI CONNECTION! ***\n\n"); Serial.print("*** LOST WIFI CONNECTION! ***\n\n");
initWifi(); initWifi();
} }
@ -221,6 +225,12 @@ int Span::getFreeSlot(){
void Span::initWifi(){ 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 char id[18]; // create string version of Accessory ID for MDNS broadcast
memcpy(id,HAPClient::accessory.ID,17); // copy ID bytes memcpy(id,HAPClient::accessory.ID,17); // copy ID bytes
id[17]='\0'; // add terminating null id[17]='\0'; // add terminating null
@ -231,7 +241,6 @@ void Span::initWifi(){
char hostName[nChars+1]; 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); 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 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 nvs_get_blob(HAPClient::wifiNVS,"WIFIDATA",&network.wifiData,&len); // retrieve data

View File

@ -53,6 +53,7 @@ struct Span{
char category[3]=""; // category ID of primary accessory - broadcast as Bonjour field "ci" (HAP Section 13) 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() unsigned long snapTime; // current time (in millis) snapped before entering Service loops() or updates()
boolean isInitialized=false; // flag indicating HomeSpan has been initialized 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 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 String configLog="\n*** Config Log ***\n\n"; // log of configuration process, including any errors

View File

@ -33,6 +33,7 @@
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// STATUS LED SETTINGS // // 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_PAIRING_NEEDED 1000,0.9 // drop-out
#define LED_ALERT 100 // rapid flashing #define LED_ALERT 100 // rapid flashing
#define LED_WIFI_CONNECTING 2000 // slow 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_STARTED 100,0.5,2,500 // rapid double-blink
#define LED_AP_CONNECTED 500,0.3,2,1000 // slow double-blink #define LED_AP_CONNECTED 500,0.3,2,1000 // slow double-blink
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
// Message Log Level Control Macros // // Message Log Level Control Macros //
// 0=Minimal, 1=Informative, 2=All // // 0=Minimal, 1=Informative, 2=All //