esp-nimble-cpp / NimBLE-Arduino  1.3.1
NimBLEService Class Reference

The model of a BLE service. More...

Public Member Functions

 NimBLEService (const char *uuid, uint16_t numHandles, NimBLEServer *pServer)
 Construct an instance of the NimBLEService. More...
 
 NimBLEService (const NimBLEUUID &uuid, uint16_t numHandles, NimBLEServer *pServer)
 Construct an instance of the BLEService. More...
 
NimBLEServergetServer ()
 Get the BLE server associated with this service. More...
 
NimBLEUUID getUUID ()
 Get the UUID of the service. More...
 
uint16_t getHandle ()
 Get the handle associated with this service. More...
 
std::string toString ()
 Return a string representation of this service. A service is defined by: More...
 
void dump ()
 Dump details of this BLE GATT service. More...
 
bool start ()
 Builds the database of characteristics/descriptors for the service and registers it with the NimBLE stack. More...
 
NimBLECharacteristiccreateCharacteristic (const char *uuid, uint32_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE)
 Create a new BLE Characteristic associated with this service. More...
 
NimBLECharacteristiccreateCharacteristic (const NimBLEUUID &uuid, uint32_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE)
 Create a new BLE Characteristic associated with this service. More...
 
void addCharacteristic (NimBLECharacteristic *pCharacteristic)
 Add a characteristic to the service. More...
 
void removeCharacteristic (NimBLECharacteristic *pCharacteristic, bool deleteChr=false)
 Remove a characteristic from the service. More...
 
NimBLECharacteristicgetCharacteristic (const char *uuid, uint16_t instanceId=0)
 Get a pointer to the characteristic object with the specified UUID. More...
 
NimBLECharacteristicgetCharacteristic (const NimBLEUUID &uuid, uint16_t instanceId=0)
 Get a pointer to the characteristic object with the specified UUID. More...
 
NimBLECharacteristicgetCharacteristicByHandle (uint16_t handle)
 Get a pointer to the characteristic object with the specified handle. More...
 
std::vector< NimBLECharacteristic * > getCharacteristics ()
 
std::vector< NimBLECharacteristic * > getCharacteristics (const char *uuid)
 
std::vector< NimBLECharacteristic * > getCharacteristics (const NimBLEUUID &uuid)
 

Detailed Description

The model of a BLE service.

Constructor & Destructor Documentation

◆ NimBLEService() [1/2]

NimBLEService::NimBLEService ( const char *  uuid,
uint16_t  numHandles,
NimBLEServer pServer 
)

Construct an instance of the NimBLEService.

Parameters
[in]uuidThe UUID of the service.
[in]numHandlesThe maximum number of handles associated with the service.
[in]pServerA pointer to the server instance that this service belongs to.

◆ NimBLEService() [2/2]

NimBLEService::NimBLEService ( const NimBLEUUID uuid,
uint16_t  numHandles,
NimBLEServer pServer 
)

Construct an instance of the BLEService.

Parameters
[in]uuidThe UUID of the service.
[in]numHandlesThe maximum number of handles associated with the service.
[in]pServerA pointer to the server instance that this service belongs to.

Member Function Documentation

◆ addCharacteristic()

void NimBLEService::addCharacteristic ( NimBLECharacteristic pCharacteristic)

Add a characteristic to the service.

Parameters
[in]pCharacteristicA pointer to the characteristic instance to add to the service.

◆ createCharacteristic() [1/2]

NimBLECharacteristic * NimBLEService::createCharacteristic ( const char *  uuid,
uint32_t  properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE 
)

Create a new BLE Characteristic associated with this service.

Parameters
[in]uuid- The UUID of the characteristic.
[in]properties- The properties of the characteristic.
Returns
The new BLE characteristic.

◆ createCharacteristic() [2/2]

NimBLECharacteristic * NimBLEService::createCharacteristic ( const NimBLEUUID uuid,
uint32_t  properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE 
)

Create a new BLE Characteristic associated with this service.

Parameters
[in]uuid- The UUID of the characteristic.
[in]properties- The properties of the characteristic.
Returns
The new BLE characteristic.

◆ dump()

void NimBLEService::dump ( )

Dump details of this BLE GATT service.

Returns
N/A.

◆ getCharacteristic() [1/2]

NimBLECharacteristic * NimBLEService::getCharacteristic ( const char *  uuid,
uint16_t  instanceId = 0 
)

Get a pointer to the characteristic object with the specified UUID.

Parameters
[in]uuidThe UUID of the characteristic.
instanceIdThe index of the characteristic to return (used when multiple characteristics have the same UUID).
Returns
A pointer to the characteristic object or nullptr if not found.

◆ getCharacteristic() [2/2]

NimBLECharacteristic * NimBLEService::getCharacteristic ( const NimBLEUUID uuid,
uint16_t  instanceId = 0 
)

Get a pointer to the characteristic object with the specified UUID.

Parameters
[in]uuidThe UUID of the characteristic.
instanceIdThe index of the characteristic to return (used when multiple characteristics have the same UUID).
Returns
A pointer to the characteristic object or nullptr if not found.

◆ getCharacteristicByHandle()

NimBLECharacteristic * NimBLEService::getCharacteristicByHandle ( uint16_t  handle)

Get a pointer to the characteristic object with the specified handle.

Parameters
handleThe handle of the characteristic.
Returns
A pointer to the characteristic object or nullptr if not found.

◆ getCharacteristics() [1/3]

std::vector< NimBLECharacteristic * > NimBLEService::getCharacteristics ( )
Returns
A vector containing pointers to each characteristic associated with this service.

◆ getCharacteristics() [2/3]

std::vector< NimBLECharacteristic * > NimBLEService::getCharacteristics ( const char *  uuid)
Returns
A vector containing pointers to each characteristic with the provided UUID associated with this service.

◆ getCharacteristics() [3/3]

std::vector< NimBLECharacteristic * > NimBLEService::getCharacteristics ( const NimBLEUUID uuid)
Returns
A vector containing pointers to each characteristic with the provided UUID associated with this service.

◆ getHandle()

uint16_t NimBLEService::getHandle ( )

Get the handle associated with this service.

Returns
The handle associated with this service.

◆ getServer()

NimBLEServer * NimBLEService::getServer ( )

Get the BLE server associated with this service.

Returns
The BLEServer associated with this service.

◆ getUUID()

NimBLEUUID NimBLEService::getUUID ( void  )

Get the UUID of the service.

Returns
the UUID of the service.

◆ removeCharacteristic()

void NimBLEService::removeCharacteristic ( NimBLECharacteristic pCharacteristic,
bool  deleteChr = false 
)

Remove a characteristic from the service.

Parameters
[in]pCharacteristicA pointer to the characteristic instance to remove from the service.
[in]deleteChrIf true it will delete the characteristic instance and free it's resources.

◆ start()

bool NimBLEService::start ( )

Builds the database of characteristics/descriptors for the service and registers it with the NimBLE stack.

Returns
bool success/failure .

◆ toString()

std::string NimBLEService::toString ( void  )

Return a string representation of this service. A service is defined by:

  • Its UUID
  • Its handle
    Returns
    A string representation of this service.