diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 2b86399..4c4480d 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -158,12 +158,8 @@ void Span::poll() { if(!strlen(network.wifiData.ssid)){ Serial.print("*** WIFI CREDENTIALS DATA NOT FOUND. "); if(autoStartAPEnabled){ - if(apFunction){ - apFunction(); - } else { - Serial.print("AUTO-START OF ACCESS POINT ENABLED...\n\n"); - processSerialCommand("A"); - } + Serial.print("AUTO-START OF ACCESS POINT ENABLED...\n\n"); + processSerialCommand("A"); } else { Serial.print("YOU MAY CONFIGURE BY TYPING 'W '.\n\n"); statusLED.start(LED_WIFI_NEEDED); @@ -775,6 +771,11 @@ void Span::processSerialCommand(const char *c){ MDNS.end(); WiFi.disconnect(); } + + if(apFunction){ + apFunction(); + return; + } network.apConfigure(); nvs_set_blob(wifiNVS,"WIFIDATA",&network.wifiData,sizeof(network.wifiData)); // update data @@ -968,7 +969,7 @@ void Span::processSerialCommand(const char *c){ /////////////////////////////// -void Span::setWifiCredentials(char *ssid, char *pwd){ +void Span::setWifiCredentials(const char *ssid, const char *pwd){ sprintf(network.wifiData.ssid,"%.*s",MAX_SSID,ssid); sprintf(network.wifiData.pwd,"%.*s",MAX_PWD,pwd); if(wifiNVS){ // is begin() already called and wifiNVS is open diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 382caf7..d1e5b14 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -108,7 +108,7 @@ struct Span{ HapQR qrCode; // optional QR Code to use for pairing const char *sketchVersion="n/a"; // version of the sketch nvs_handle charNVS; // handle for non-volatile-storage of Characteristics data - nvs_handle wifiNVS=NULL; // handle for non-volatile-storage of WiFi data + nvs_handle wifiNVS=0; // handle for non-volatile-storage of WiFi data boolean connected=false; // WiFi connection status unsigned long waitTime=60000; // time to wait (in milliseconds) between WiFi connection attempts @@ -127,8 +127,8 @@ struct Span{ boolean otaAuth; // OTA requires password when set to true void (*wifiCallback)()=NULL; // optional callback function to invoke once WiFi connectivity is established boolean autoStartAPEnabled=false; // enables auto start-up of Access Point when WiFi Credentials not found - void (*apFunction)()=NULL; // optional function to invoke when using enableAutoStartAP() - + void (*apFunction)()=NULL; // optional function to invoke when starting Access Point + WiFiServer *hapServer; // pointer to the HAP Server connection Blinker statusLED; // indicates HomeSpan status PushButton controlButton; // controls HomeSpan configuration and resets @@ -182,9 +182,10 @@ struct Span{ void setSketchVersion(const char *sVer){sketchVersion=sVer;} // set optional sketch version number const char *getSketchVersion(){return sketchVersion;} // get sketch version number void setWifiCallback(void (*f)()){wifiCallback=f;} // sets an optional user-defined function to call once WiFi connectivity is established + void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point - void enableAutoStartAP(void (*f)()=NULL){autoStartAPEnabled=true;apFunction=f;} // enables auto start-up of Access Point when WiFi Credentials not found (will call optional f, if specified) - void setWifiCredentials(char *ssid, char *pwd); // sets WiFi Credentials + void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found + void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials }; /////////////////////////////// diff --git a/src/src.ino b/src/src.ino index df77f94..2a2a0a8 100644 --- a/src/src.ino +++ b/src/src.ino @@ -21,7 +21,8 @@ void setup() { new SpanUserCommand('d',"My Description",userCom1); new SpanUserCommand('d',"My second Description",userCom2); - homeSpan.enableAutoStartAP(myWiFiAP); +// homeSpan.enableAutoStartAP(); +// homeSpan.setApFunction(myWiFiAP); homeSpan.begin(Category::Lighting,"HomeSpan Lamp Server","homespan");