Skip to content

Commit

Permalink
Added advertise and isConnected functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Paris Molver committed Sep 7, 2022
1 parent 03a15b8 commit 16a08a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/DashioESP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/DashioESP.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class DashioBLE {
bool printMessages;
DashioDevice *dashioDevice;
BLEServer *pServer;
BLEService *pService;
BLEAdvertising *pAdvertising;
BLECharacteristic *pCharacteristic;

void bleNotifyValue(const String& message);
Expand All @@ -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
Expand Down

0 comments on commit 16a08a3

Please sign in to comment.