Open
Description
I have a simple application that I want to be able to start and stop advertising so that other devices are prevented from connecting when I don't want them too. This needs to be turned on and off at runtime.
Here is my startup code:
pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
pServer->setCallbacks(new BTServerCallbacks());
pCharacteristicCommand = pService->createCharacteristic(
COMMAND_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY
);
pCharacteristicCommand->setCallbacks(new BTCallbacks());
pCharacteristicCommand->setValue("");
pCharacteristicCommand->addDescriptor(new BLE2902());
pService->start();
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
This works great and my service advertises and I am able to connect with it and process things.
Then when I want my device to become unavailable I do this:
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->stop();
It calls it and doesn't give any errors or exceptions, but my device is still visible to my iPhone and I can still connect to it.
How do I disable advertising and connecting during runtime?