Arduino Function: BLEPeripheral.addRemoteAttribute




This function can be used when the board acts as client to indicate the attributes (services, characteristics and descriptors) the board wants to query to the server.

The usage of this function is the same as addAttribute function. It is needed to follow the BLE standard to insert attributes in the right order. Refer to addAttribute function to have further information.




  • remoteService: BLERemoteAttribute&. Remote Service, characteristic or descriptor object.




 Written by Chiara Ruggeri (
 This example shows the client capabilities of the BLEPeripheral library.
 It acts as a CTS client and recovers the current date and time from a central every time USER1 button is pressed.
 The informations are transmitted as a string. A parse to byte type is needed to read the correct values.
 You can use nRFConnect app to set up a CTS server or use another board with CTSServer example in File->Examples->BLE->Central menu.
 To have further informations about the CTS service please refer to the Bluetooth specifications:

 This example code is in the public domain.

#include <BLEPeripheral.h>
#include <LowPower.h>

char * months [] = {"Unknown", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
char * days [] = {"Unknown", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

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

// create remote service with UUID compliant to CTS service
BLERemoteService              remoteCtsService         = BLERemoteService("1805");

// create remote characteristics with UUID and properties compliant to CTS service
BLERemoteCharacteristic       remoteCtsCharacteristic        = BLERemoteCharacteristic("2a2b", BLERead | BLENotify);

void setup() {

 // set device name and appearance
 blePeripheral.setDeviceName("CTS client");

  // assign event handlers for connected, disconnected to peripheral
 blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
 blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
 blePeripheral.setEventHandler(BLERemoteServicesDiscovered, blePeripheralRemoteServicesDiscoveredHandler);

 // assign event handlers for characteristic
 remoteCtsCharacteristic.setEventHandler(BLEValueUpdated, bleRemoteCtsCharacteristicValueUpdatedHandle);

 // begin initialization

 attachInterrupt(USER1_BUTTON, readTime, LOW);
 Serial.println(F("BLE Peripheral - cts"));

void loop() {
 // put the board in standby mode to save power

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

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

void blePeripheralRemoteServicesDiscoveredHandler(BLECentral& central) {
 // central remote services discovered event handler
 Serial.print(F("Remote services discovered event, central: "));
 if (remoteCtsCharacteristic.canRead()) {;

void bleRemoteCtsCharacteristicValueUpdatedHandle(BLECentral& central, BLERemoteCharacteristic& characteristic) {
 // copy the time value in a local variable
 memset(currentTime, 0, sizeof(currentTime));
 memcpy(currentTime, remoteCtsCharacteristic.value(), remoteCtsCharacteristic.valueLength());

 // year is the first two bytes of the string
 byte first=currentTime[0];
 byte second=currentTime[1];
 uint16_t year=first | (second << 8);

 // month is the third byte
 byte month = currentTime[2];

 // day, hours, minutes and seconds follow
 byte day = currentTime[3];
 byte hours = currentTime[4];
 byte minutes = currentTime[5];
 byte seconds = currentTime[6];

 // day of the week
 byte dow = currentTime[7];

 // 1/256th of a second
 byte fraction = currentTime[8];

 // Print current time
 Serial.println("*** Current Time received ***");
 Serial.print(" ");
 Serial.print(" ");
 Serial.print(", ");
 Serial.print("Day of the week: ");
 Serial.print("Fractions: ");
 Serial.println(" / 256 s");

void readTime(){;

Written by