From 16a08a3fee8054151b70832becd51647644b2ba3 Mon Sep 17 00:00:00 2001 From: Paris Molver Date: Thu, 8 Sep 2022 01:39:59 +1200 Subject: [PATCH] Added advertise and isConnected functions --- src/DashioESP.cpp | 15 +++++++++++++-- src/DashioESP.h | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/DashioESP.cpp b/src/DashioESP.cpp index ba95513..502d6c3 100644 --- a/src/DashioESP.cpp +++ b/src/DashioESP.cpp @@ -579,13 +579,12 @@ void DashioBLE::begin(bool secureBLE) { // Setup server, service and characteristic pServer = BLEDevice::createServer(); - BLEService *pService = pServer->createService(SERVICE_UUID); + pService = pServer->createService(SERVICE_UUID); pCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_WRITE_NR | BLECharacteristic::PROPERTY_NOTIFY ); pCharacteristic->setCallbacks(new messageReceivedBLECallback(this)); pService->start(); // Setup BLE advertising - BLEAdvertising *pAdvertising; pAdvertising = BLEDevice::getAdvertising(); pAdvertising->addServiceUUID(BLEUUID(SERVICE_UUID)); pAdvertising->setScanResponse(true); @@ -599,6 +598,18 @@ String DashioBLE::macAddress() { return bdAddr.toString().c_str(); } +void DashioBLE::advertise(){ + pAdvertising->start(); +} + +bool DashioBLE::isConnected(){ + if (pServer->getConnectedCount() > 0) { + return true; + } else { + return false; + } +} + // ------------------------------------------------------------------------------------- #endif diff --git a/src/DashioESP.h b/src/DashioESP.h index fa16546..80f8beb 100644 --- a/src/DashioESP.h +++ b/src/DashioESP.h @@ -119,6 +119,8 @@ class DashioBLE { bool printMessages; DashioDevice *dashioDevice; BLEServer *pServer; + BLEService *pService; + BLEAdvertising *pAdvertising; BLECharacteristic *pCharacteristic; void bleNotifyValue(const String& message); @@ -132,6 +134,8 @@ class DashioBLE { void run(); void setCallback(void (*processIncomingMessage)(MessageData *messageData)); void begin(bool secureBLE = false); + void advertise(); + bool isConnected(); String macAddress(); }; #endif