I was working on a remote sensor using the Adafruit Pro Tinket and the Bluetooth (BT) Low Energy nRF8001 breakout board.
I wanted to be able to disconnect the sensor and then prevent the BT radio from going into advertisement mode for a period of time, then re-start advertisement mode to have better battery life.
But .. I could not find a way to do this using the Adafruit BLE library, there is no method to do this. Now the Adafruit library makes calls to the Nordic nRF8001 driver interface. Wow .. this interface does support a disconnect function.
This instructible: Shows you how to add support in the Adafruit BLE library to be able to disconnect the radio, and save power , which you can call from your own programs.
We are going to add a new method to Adafruit BLE UART class.
Step 1: You Need to Modify the Adafruit_BLE_UART.h File
This file is in the IDE libraries folder ..\libraries\Adafruit_BLE_UART\Adafruit_BLE_UART.h
Just be be safe , copy this file first.
Using a text editor open the file and locate this:
class Adafruit_BLE_UART : public Stream
At the end of the public section just before the private section .. add this.
Step 2: You Need to Modify Adafruit_BLE_UART.cpp File
You can find this file in the same folder as Adafruit_BLE_UART.h file.
Once again save the original file.
Open this file with a text editor and add this:
// added this
// Calls bool lib_aci_disconnect(aci_state_t *aci_stat, aci_disconnect_reason_t reason)
bool result = lib_aci_disconnect(&aci_state, ACI_REASON_TERMINATE);
Step 3: To Call BT Disconnect From Your Program
Call the Force_Disconnect() function below:
if(ACI_EVT_CONNECTED != BTLEserial.getState())
// This call does the disconnect