Arduino Function: BLECentralRole.printBleMessage




Print useful information about the BLE status.
This function has to be called after to have received a BLEMessage event. See setEventHandler function to know how to set a callback for incoming events.


  • evtCode: int. Code detecting the type of the current message.
  • messageCode: int. Code detecting the specific message.




/* showPasskeyCentral.ino

  Written by Chiara Ruggeri (

  This example shows how to enable bonding features on BLECentral module.
  To know all the possible bonding types please refer to the documentation.
  To delete bond information an interrupt has been attached to USER1_BUTTON (in Primo board).
  If you're using a Primo Core connect a button to the board and change USER1_BUTTON with the number of pin the button is connected to.
  Use the complementary example enterPasskeyBond.ino in File->Examples->BLE->Peripheral->Bonding to test this feature.
  In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is scanning.
  It will be on when the board is connected to a peripheral. It will be off when the board is disconnected.

  This example code is in the public domain.

#include <BLECentralRole.h>

// create central instance
BLECentralRole                bleCentral                 = BLECentralRole();

// create remote service
BLERemoteService              dummyRemoteService               = BLERemoteService("19b10010e8f2537e4f6cd104768a1214");

// create remote characteristics
BLERemoteCharacteristic       dummyRemoteCharacteristic        = BLERemoteCharacteristic("19b10011e8f2537e4f6cd104768a1214", BLERead | BLEWrite);


void setup() {
 attachInterrupt(BUTTON, deleteBondInformation, LOW);

 //initialize BLE led
 pinMode(BLE_LED, OUTPUT);

 // add service and characteristic

 // enable bonding and set the type

 // assign event handlers
 bleCentral.setEventHandler(BLEScanReceived, receiveAdvPck);
 bleCentral.setEventHandler(BLEConnected, bleCentralConnectHandler);
 bleCentral.setEventHandler(BLEDisconnected, bleCentralDisconnectHandler);
 bleCentral.setEventHandler(BLEPasskeyReceived, showPasskey);
 bleCentral.setEventHandler(BLEBonded, bond);

 // use BLEMessage event handler to retrieve information about internal BLE status
 bleCentral.setEventHandler(BLEMessage, receiveMessage);

 // begin initialization

 Serial.println(F("BLE Bonding example"));

void loop() {
 // Handle BLE led

void blinkOnScan(){
 // retrieve the central status in order to blink only when scanning
 if(bleCentral.status() == SCANNING){
digitalWrite(BLE_LED, LOW);
digitalWrite(BLE_LED, HIGH);

void receiveAdvPck(BLEPeripheralPeer& peer){
 char advertisedName[31];
 byte len;

 // search for a device that advertises "BONDExample" name
 peer.getFieldInAdvPck(BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME, advertisedName, len);

 if(len == 0) // field not found
  peer.getFieldInAdvPck(BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, advertisedName, len);

 if(len != 0){ // the field was found

if(!strcmp(advertisedName, "BONDExample"))
  // Name found. Connect to the peripheral

void bleCentralConnectHandler(BLEPeripheralPeer& peer) {
 // peer connected event handler
 Serial.print("Connected event, peripheral: ");

 // turn BLE_LED on
 digitalWrite(BLE_LED, HIGH);

void bleCentralDisconnectHandler(BLEPeripheralPeer& peer) {
 // peer disconnected event handler
 Serial.print("Disconnected event, peripheral: ");

 // turn BLE_LED off
 digitalWrite(BLE_LED, LOW);

void showPasskey(BLEPeripheralPeer& peer) {
 // passkey generated event handler
 Serial.print("Please type this passkey on the other device = ");

void bond(BLEPeripheralPeer& peer) {
 // central bonded event handler

void deleteBondInformation(){
 // button has been pressed. Delete bond
 Serial.println("Bond data cleared");

void receiveMessage(int evtCode, int messageCode){
 bleCentral.printBleMessage(evtCode, messageCode);

Written by