AdafruitBluefruit

Adafruit's nRF52 BSP codebase is still undergoing active development based on customer feedback and testing. As such, the class documentation here may be incomplete, and you should consult the Github repo for the latest code and API developments: https://goo.gl/LdEx62

This base class is the main entry point to the Adafruit Bluefruit nRF52 API, and exposes most of the helper classes and functions that you use to configure your device.

API

AdafruitBluefruit has the following public API:

Download: file
// Constructor
AdafruitBluefruit(void);

/*------------------------------------------------------------------*/
/* Lower Level Classes (Bluefruit.Advertising.*, etc.)
 *------------------------------------------------------------------*/
BLEGap             Gap;
BLEGatt            Gatt;

BLEAdvertising     Advertising;
BLEAdvertisingData ScanResponse;
BLEScanner         Scanner;
BLECentral         Central;
BLEDiscovery       Discovery;

/*------------------------------------------------------------------*/
/* SoftDevice Configure Functions, must call before begin().
 * These function affect the SRAM consumed by SoftDevice.
 *------------------------------------------------------------------*/
void     configServiceChanged (bool     changed);
void     configUuid128Count   (uint8_t  uuid128_max);
void     configAttrTableSize  (uint32_t attr_table_size);

// Config Bandwidth for connections
void     configPrphConn        (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
void     configCentralConn     (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);

// Convenient function to config connection
void     configPrphBandwidth   (uint8_t bw);
void     configCentralBandwidth(uint8_t bw);

err_t    begin(uint8_t prph_count = 1, uint8_t central_count = 0);

/*------------------------------------------------------------------*/
/* General Functions
 *------------------------------------------------------------------*/
void     setName            (const char* str);
uint8_t  getName            (char* name, uint16_t bufsize);

bool     setTxPower         (int8_t power);
int8_t   getTxPower         (void);

bool     setApperance       (uint16_t appear);
uint16_t getApperance       (void);

void     autoConnLed        (bool enabled);
void     setConnLedInterval (uint32_t ms);

/*------------------------------------------------------------------*/
/* GAP, Connections and Bonding
 *------------------------------------------------------------------*/
bool     connected         (void);
bool     disconnect        (void);

bool     setConnInterval   (uint16_t min, uint16_t max);
bool     setConnIntervalMS (uint16_t min_ms, uint16_t max_ms);

uint16_t connHandle        (void);
bool     connPaired        (void);
uint16_t connInterval      (void);

bool     requestPairing    (void);
void     clearBonds        (void);

ble_gap_addr_t getPeerAddr (void);
uint8_t        getPeerAddr (uint8_t addr[6]);

void     printInfo(void);

/*------------------------------------------------------------------*/
/* Callbacks
 *------------------------------------------------------------------*/
void setConnectCallback   ( BLEGap::connect_callback_t    fp);
void setDisconnectCallback( BLEGap::disconnect_callback_t fp);

These functions are generally available via 'Bluefruit.*'. For example, to check the connection status in your sketch you could run 'if (Bluefruit.connected()) { ... }'.

Examples

For examples of how to work with the parent Bluefruit class, see the Examples section later in this guide. It's better to examine this class in the context of a real world use case.

You can also browse the latest example code online via Github:

This guide was first published on Mar 22, 2017. It was last updated on Mar 22, 2017. This page (AdafruitBluefruit) was last updated on Jul 17, 2019.