updated enableAutoStartAP to accept user-define function as argument

This commit is contained in:
Gregg 2021-06-19 21:36:18 -05:00
parent b53081dfc7
commit e3d081bb35
3 changed files with 16 additions and 4 deletions

View File

@ -147,8 +147,12 @@ void Span::poll() {
if(!strlen(network.wifiData.ssid)){
Serial.print("*** WIFI CREDENTIALS DATA NOT FOUND. ");
if(autoStartAPEnabled){
Serial.print("AUTO-START OF ACCESS POINT ENABLED...\n\n");
processSerialCommand("A");
if(apFunction){
apFunction();
} else {
Serial.print("AUTO-START OF ACCESS POINT ENABLED...\n\n");
processSerialCommand("A");
}
} else {
Serial.print("YOU MAY CONFIGURE BY TYPING 'W <RETURN>'.\n\n");
statusLED.start(LED_WIFI_NEEDED);

View File

@ -126,6 +126,7 @@ 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()
WiFiServer *hapServer; // pointer to the HAP Server connection
Blinker statusLED; // indicates HomeSpan status
@ -180,7 +181,8 @@ 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 enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
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)
};
///////////////////////////////

View File

@ -21,7 +21,7 @@ void setup() {
new SpanUserCommand('d',"My Description",userCom1);
new SpanUserCommand('d',"My second Description",userCom2);
// homeSpan.enableAutoStartAP();
// homeSpan.enableAutoStartAP(myWiFiAP);
homeSpan.begin(Category::Lighting,"HomeSpan Lamp Server","homespan");
@ -60,6 +60,12 @@ void loop(){
//////////////////////////////////////
void myWiFiAP(){
Serial.print("Calling My WIFI AP\n\n");
}
//////////////////////////////////////
void wifiEstablished(){
Serial.print("IN CALLBACK FUNCTION\n\n");
}