Arduino Function: BLEPeripheral.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.


blePeripheral.printBleMessage(evtCode, messageCode);


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

  • messageCode: int. Code detecting the specific message.




/* showPasskey.ino

  Written by Chiara Ruggeri (

  This example shows how to enable bonding features on BLEPeripheral 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 enterPasskeyCentral.ino in File->Examples->BLE->Central->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 advertising.
  It will be on when the board is connected to a central. It will be off when the board is disconnected.
  This example code is in the public domain.

#include <BLEPeripheral.h>

// create peripheral instance
BLEPeripheral        blePeripheral     = BLEPeripheral();

// create service
BLEService           dummyService        = BLEService("19b10000e8f2537e4f6cd104768a1214");

// create characteristic
BLECharCharacteristic   dummyCharacteristic = BLECharCharacteristic("19b10001e8f2537e4f6cd104768a1214", BLERead | BLEWrite);


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

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

 // set advertised local name and service UUID

 // add service and characteristic

 //enable bonding and set the type

 // assign event handlers for connected, disconnected, passkey received and bond to peripheral
 blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
 blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
 blePeripheral.setEventHandler(BLEPasskeyReceived, showPasskey);
 blePeripheral.setEventHandler(BLEBonded, bond);

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

 // begin initialization

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

void loop() {
 // blink if the board is advertising

void blinkOnAdv(){
 // retrieve the peripheral status in order to blink only when advertising
 if(blePeripheral.status() == ADVERTISING){
digitalWrite(BLE_LED, LOW);
digitalWrite(BLE_LED, HIGH);

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

void bond(BLECentral& central) {
 // central bonded event handler

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

void blePeripheralConnectHandler(BLECentral& central) {
 // central connected event handler
 Serial.print(F("Connected event, central: "));

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

void blePeripheralDisconnectHandler(BLECentral& central) {
 // central disconnected event handler
 Serial.print(F("Disconnected event, central: "));

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

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

Written by