From e3d081bb35138e928bef0c77695ac80523d00f36 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 19 Jun 2021 21:36:18 -0500 Subject: [PATCH] updated enableAutoStartAP to accept user-define function as argument --- src/HomeSpan.cpp | 8 ++++++-- src/HomeSpan.h | 4 +++- src/src.ino | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 381f1e3..a2a5c40 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -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 '.\n\n"); statusLED.start(LED_WIFI_NEEDED); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index b723080..a951077 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -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) }; /////////////////////////////// diff --git a/src/src.ino b/src/src.ino index 9e67e91..905bb71 100644 --- a/src/src.ino +++ b/src/src.ino @@ -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"); }