<span class="wikiword">ble.addService()</span>

Description

Initializes a service and its characteristics and registers them with the NP. Services and characteristics should not be directly modified after they are added.

Syntax

ble.addService(&service);

Parameters

service: Pointer to an instance of [BLE\_Service](http://energia.nu/reference/ble/ble-addservice/ble_service/). This and the contained [BLE\_Char’s](http://energia.nu/reference/ble/ble-addservice/ble_char/) should just be statically declared and initialized by the Energia user as shown in the example.

Example

#include <BLE.h>
int heartRateMeasurement = 0;
BLE_Char heartRateChar =
{
  {0x37, 0x2A}, // UUID for heart rate measurement
  BLE_READABLE, // The BLE client is able to only read this characterisitic value
  "Heart rate measurement" // Description shown to the client
};
/* This syntax lets services have any number of characteristics. */
BLE_Char *heartRateChars[] = {&heartRateChar};
BLE_Service heartRateService =
{
  {0x0D, 0x18}, // UUID for heart rate service
  1, heartRateChars
};
void setup() {
  /* Start the BLE layer and connect to the network processor. */
  ble.begin();
/* Add the heart rate service. */
ble.addService(&heartRateService);
  /* Sets the characteristic value's type. Note that this can be changed by
  calling writeValue with a differently typed variable. */
  ble.writeValue(&heartRateChar, heartRateMeasurement);
}
void loop() {
  ble.handleEvents();
}

[Reference Home](http://energia.nu/reference/ "Reference"){.wikilink}<span style="color: #202020;"> || </span>[BLE Library](http://energia.nu/reference/ble/ "WiFi")