Datasheet

We are then ready to forward data from central to peripheral and vice versa using callbacks:
Peripheral Role
The first thing to do for the peripheral part of our code is to setup the connect callback, which fires when a connection
is established/disconnected with the central. Alternatively you could poll the connection status with connected(), but
callbacks helps to simplify the code significantly:
Central Role
Next we setup the Central mode connect callback, which fires when a connection is established/disconnected with a
peripheral device:
void cent_bleuart_rx_callback(BLEClientUart& cent_uart)
{
char str[20+1] = { 0 };
cent_uart.read(str, 20);
Serial.print("[Cent] RX: ");
Serial.println(str);
if ( bleuart.notifyEnabled() )
{
// Forward data from our peripheral to Mobile
bleuart.print( str );
}else
{
// response with no prph message
clientUart.println("[Cent] Peripheral role not connected");
}
}
void prph_bleuart_rx_callback(void)
{
// Forward data from Mobile to our peripheral
char str[20+1] = { 0 };
bleuart.read(str, 20);
Serial.print("[Prph] RX: ");
Serial.println(str);
if ( clientUart.discovered() )
{
clientUart.print(str);
}else
{
bleuart.println("[Prph] Central role not connected");
}
}
// Callbacks for Peripheral
Bluefruit.setConnectCallback(prph_connect_callback);
Bluefruit.setDisconnectCallback(prph_disconnect_callback);
© Adafruit Industries https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide Page 77 of 175