Added WiFi callback functionality

HomeSpan will call a user-defined function upon establishing WiFi connectivity.
Set function with homeSpan.setWifiCallback(f), where f must be of form void f().
This commit is contained in:
Gregg 2021-02-11 07:27:29 -06:00
parent 3a519bdc54
commit 7e03998865
3 changed files with 14 additions and 2 deletions

View File

@ -495,6 +495,9 @@ void Span::checkConnect(){
} else {
statusLED.on();
}
if(wifiCallback)
wifiCallback();
} // initWiFi

View File

@ -103,6 +103,7 @@ struct Span{
char qrID[5]=""; // Setup ID used for pairing with QR Code
boolean otaEnabled=false; // enables Over-the-Air ("OTA") updates
char otaPwd[33]; // MD5 Hash of OTA password, represented as a string of hexidecimal characters
void (*wifiCallback)()=NULL; // optional callback function to invoke once WiFi connectivity is established
WiFiServer *hapServer; // pointer to the HAP Server connection
Blinker statusLED; // indicates HomeSpan status
@ -156,6 +157,7 @@ struct Span{
void enableOTA(){otaEnabled=true;} // enables Over-the-Air updates
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
};
///////////////////////////////

View File

@ -14,8 +14,9 @@ void setup() {
homeSpan.setPortNum(1200);
homeSpan.setMaxConnections(16);
// homeSpan.setQRID("One1");
// homeSpan.enableOTA();
homeSpan.setSketchVersion("Test 1.2.3");
homeSpan.enableOTA();
homeSpan.setSketchVersion("Test 1.2.4");
homeSpan.setWifiCallback(wifiEstablished);
homeSpan.begin(Category::Lighting,"HomeSpanTest");
@ -44,3 +45,9 @@ void loop(){
homeSpan.poll();
} // end of loop()
//////////////////////////////////////
void wifiEstablished(){
Serial.println("\n\nIN CALLBACK FUNCTION\n\n");
}