esp-nimble-cpp 2.0.2
Loading...
Searching...
No Matches
NimBLEService Class Reference

The model of a BLE service. More...

#include <NimBLEService.h>

Inherits NimBLELocalAttribute.

Public Member Functions

 NimBLEService (const char *uuid)
 Construct an instance of the NimBLEService.
 
 NimBLEService (const NimBLEUUID &uuid)
 Construct an instance of the BLEService.
 
 ~NimBLEService ()
 Destructor, make sure we release the resources allocated for the service.
 
NimBLEServergetServer () const
 Get the BLE server associated with this service.
 
std::string toString () const
 Return a string representation of this service. A service is defined by:
 
void dump () const
 Dump details of this BLE GATT service.
 
bool isStarted () const
 Checks if the service has been started.
 
bool start ()
 Builds the database of characteristics/descriptors for the service and registers it with the NimBLE stack.
 
NimBLECharacteristiccreateCharacteristic (const char *uuid, uint32_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t max_len=BLE_ATT_ATTR_MAX_LEN)
 Create a new BLE Characteristic associated with this service.
 
NimBLECharacteristiccreateCharacteristic (const NimBLEUUID &uuid, uint32_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t max_len=BLE_ATT_ATTR_MAX_LEN)
 Create a new BLE Characteristic associated with this service.
 
void addCharacteristic (NimBLECharacteristic *pCharacteristic)
 Add a characteristic to the service.
 
void removeCharacteristic (NimBLECharacteristic *pCharacteristic, bool deleteChr=false)
 Remove a characteristic from the service.
 
NimBLECharacteristicgetCharacteristic (const char *uuid, uint16_t instanceId=0) const
 Get a pointer to the characteristic object with the specified UUID.
 
NimBLECharacteristicgetCharacteristic (const NimBLEUUID &uuid, uint16_t instanceId=0) const
 Get a pointer to the characteristic object with the specified UUID.
 
NimBLECharacteristicgetCharacteristicByHandle (uint16_t handle) const
 Get a pointer to the characteristic object with the specified handle.
 
const std::vector< NimBLECharacteristic * > & getCharacteristics () const
 
std::vector< NimBLECharacteristic * > getCharacteristics (const char *uuid) const
 
std::vector< NimBLECharacteristic * > getCharacteristics (const NimBLEUUID &uuid) const
 
- Public Member Functions inherited from NimBLELocalAttribute
uint8_t getRemoved () const
 Get the removed flag.
 
- Public Member Functions inherited from NimBLEAttribute
const NimBLEUUIDgetUUID () const
 Get the UUID of the attribute.
 
uint16_t getHandle () const
 Get the handle of the attribute.
 

Additional Inherited Members

- Protected Member Functions inherited from NimBLELocalAttribute
 NimBLELocalAttribute (const NimBLEUUID &uuid, uint16_t handle)
 Construct a local attribute.
 
 ~NimBLELocalAttribute ()=default
 Destroy the local attribute.
 
void setRemoved (uint8_t removed)
 Set the removed flag.
 
- Protected Member Functions inherited from NimBLEAttribute
 NimBLEAttribute (const NimBLEUUID &uuid, uint16_t handle)
 Construct a new NimBLEAttribute object.
 
 ~NimBLEAttribute ()=default
 Destroy the NimBLEAttribute object.
 

Detailed Description

The model of a BLE service.

Constructor & Destructor Documentation

◆ NimBLEService() [1/2]

NimBLEService::NimBLEService ( const char *  uuid)

Construct an instance of the NimBLEService.

Parameters
[in]uuidThe UUID of the service.

◆ NimBLEService() [2/2]

NimBLEService::NimBLEService ( const NimBLEUUID uuid)

Construct an instance of the BLEService.

Parameters
[in]uuidThe UUID of the service.

Member Function Documentation

◆ addCharacteristic()

void NimBLEService::addCharacteristic ( NimBLECharacteristic pChar)

Add a characteristic to the service.

Parameters
[in]pCharA 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,
uint16_t  max_len = BLE_ATT_ATTR_MAX_LEN 
)

Create a new BLE Characteristic associated with this service.

Parameters
[in]uuid- The UUID of the characteristic.
[in]properties- The properties of the characteristic.
[in]max_len- The maximum length in bytes that the characteristic value can hold.
Returns
The new BLE characteristic.

◆ createCharacteristic() [2/2]

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

Create a new BLE Characteristic associated with this service.

Parameters
[in]uuid- The UUID of the characteristic.
[in]properties- The properties of the characteristic.
[in]max_len- The maximum length in bytes that the characteristic value can hold.
Returns
The new BLE characteristic.

◆ getCharacteristic() [1/2]

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

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

Parameters
[in]uuidThe UUID of the characteristic.
idxThe 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  idx = 0 
) const

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

Parameters
[in]uuidThe UUID of the characteristic.
idxThe 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) const

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]

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

◆ getCharacteristics() [2/3]

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

◆ getServer()

NimBLEServer * NimBLEService::getServer ( ) const

Get the BLE server associated with this service.

Returns
The BLEServer associated with this service.

◆ isStarted()

bool NimBLEService::isStarted ( ) const

Checks if the service has been started.

Returns
True if the service has been started.

◆ removeCharacteristic()

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

Remove a characteristic from the service.

Parameters
[in]pCharA 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 ( ) const

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

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