From 7e03998865007eefe17792dde48e39bb104ab8c7 Mon Sep 17 00:00:00 2001 From: Gregg Date: Thu, 11 Feb 2021 07:27:29 -0600 Subject: [PATCH] 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(). --- src/HomeSpan.cpp | 3 +++ src/HomeSpan.h | 2 ++ src/src.ino | 11 +++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 41851a3..da6360f 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -495,6 +495,9 @@ void Span::checkConnect(){ } else { statusLED.on(); } + + if(wifiCallback) + wifiCallback(); } // initWiFi diff --git a/src/HomeSpan.h b/src/HomeSpan.h index ac11576..00250b0 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -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 }; /////////////////////////////// diff --git a/src/src.ino b/src/src.ino index b12712f..3869a79 100644 --- a/src/src.ino +++ b/src/src.ino @@ -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"); +}