Adafruit Bluetooth Hack

by MikeC180 in Circuits > Arduino

1376 Views, 11 Favorites, 0 Comments

Adafruit Bluetooth Hack

20160108_153300.jpg

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.

You Need to Modify the Adafruit_BLE_UART.h File

569143f650e1b6ef940002b3.jpeg

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
{ public:

At the end of the public section just before the private section .. add this.

void disconnect(void);


Save file

You Need to Modify Adafruit_BLE_UART.cpp File

56914425937ddb2623001770.jpeg

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)

void Adafruit_BLE_UART::disconnect(void)

{

bool result = lib_aci_disconnect(&aci_state, ACI_REASON_TERMINATE);

}

Save file

To Call BT Disconnect From Your Program

Call the Force_Disconnect() function below:

void Force_Disconnect(void)

{

BTLEserial.pollACI();

if(ACI_EVT_CONNECTED != BTLEserial.getState())

{

return;

}

// This call does the disconnect

BTLEserial.disconnect();

}