NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
NimBLEAdvertisementData Class Reference

Advertisement data set by the programmer to be published by the BLE server. More...

#include <NimBLEAdvertisementData.h>

Public Member Functions

bool addData (const uint8_t *data, size_t length)
 Add data to the payload to be advertised.
 
bool addData (const std::vector< uint8_t > &data)
 Add data to the payload to be advertised.
 
bool setAppearance (uint16_t appearance)
 Set the appearance.
 
bool setFlags (uint8_t)
 Set the advertisement flags.
 
bool addTxPower ()
 Adds Tx power level to the advertisement data.
 
bool setPreferredParams (uint16_t minInterval, uint16_t maxInterval)
 Set the preferred min and max connection intervals to advertise.
 
bool addServiceUUID (const NimBLEUUID &serviceUUID)
 Add a service uuid to exposed list of services.
 
bool addServiceUUID (const char *serviceUUID)
 Add a service uuid to exposed list of services.
 
bool removeServiceUUID (const NimBLEUUID &serviceUUID)
 Remove a service UUID from the advertisement.
 
bool removeServiceUUID (const char *serviceUUID)
 Remove a service UUID from the advertisement.
 
bool removeServices ()
 Remove all service UUIDs from the advertisement.
 
bool setManufacturerData (const uint8_t *data, size_t length)
 Set manufacturer specific data.
 
bool setManufacturerData (const std::string &data)
 Set manufacturer specific data.
 
bool setManufacturerData (const std::vector< uint8_t > &data)
 Set manufacturer specific data.
 
bool setURI (const std::string &uri)
 Set the URI to advertise.
 
bool setName (const std::string &name, bool isComplete=true)
 Set the complete name of this device.
 
bool setShortName (const std::string &name)
 Set the short name.
 
bool setCompleteServices (const NimBLEUUID &uuid)
 Set a single service to advertise as a complete list of services.
 
bool setCompleteServices16 (const std::vector< NimBLEUUID > &uuids)
 Set the complete list of 16 bit services to advertise.
 
bool setCompleteServices32 (const std::vector< NimBLEUUID > &uuids)
 Set the complete list of 32 bit services to advertise.
 
bool setPartialServices (const NimBLEUUID &uuid)
 Set a single service to advertise as a partial list of services.
 
bool setPartialServices16 (const std::vector< NimBLEUUID > &uuids)
 Set the partial list of services to advertise.
 
bool setPartialServices32 (const std::vector< NimBLEUUID > &uuids)
 Set the partial list of services to advertise.
 
bool setServiceData (const NimBLEUUID &uuid, const uint8_t *data, size_t length)
 Set the service data advertised for the UUID.
 
bool setServiceData (const NimBLEUUID &uuid, const std::string &data)
 Set the service data (UUID + data)
 
bool setServiceData (const NimBLEUUID &uuid, const std::vector< uint8_t > &data)
 Set the service data advertised for the UUID.
 
bool removeData (uint8_t type)
 Remove data from the advertisement data.
 
void clearData ()
 Clear the advertisement data for reuse.
 
int getDataLocation (uint8_t type) const
 Get the location of the data in the payload.
 
std::string toString () const
 Get the string representation of the advertisement data.
 
std::vector< uint8_t > getPayload () const
 Retrieve the payload that is to be advertised.
 

Detailed Description

Advertisement data set by the programmer to be published by the BLE server.

Member Function Documentation

◆ addData() [1/2]

bool NimBLEAdvertisementData::addData ( const std::vector< uint8_t > &  data)

Add data to the payload to be advertised.

Parameters
[in]dataThe data to be added to the payload.

◆ addData() [2/2]

bool NimBLEAdvertisementData::addData ( const uint8_t *  data,
size_t  length 
)

Add data to the payload to be advertised.

Parameters
[in]dataThe data to be added to the payload.
[in]lengthThe size of data to be added to the payload.

◆ addServiceUUID() [1/2]

bool NimBLEAdvertisementData::addServiceUUID ( const char *  serviceUUID)

Add a service uuid to exposed list of services.

Parameters
[in]serviceUUIDThe string representation of the service to expose.
Returns
True if successful.

◆ addServiceUUID() [2/2]

bool NimBLEAdvertisementData::addServiceUUID ( const NimBLEUUID serviceUUID)

Add a service uuid to exposed list of services.

Parameters
[in]serviceUUIDThe UUID of the service to expose.

◆ addTxPower()

bool NimBLEAdvertisementData::addTxPower ( )

Adds Tx power level to the advertisement data.

Returns
True if successful.

◆ getDataLocation()

int NimBLEAdvertisementData::getDataLocation ( uint8_t  type) const

Get the location of the data in the payload.

Parameters
[in]typeThe type of data to search for.
Returns
-1 if the data is not found, otherwise the index of the data in the payload.

◆ getPayload()

std::vector< uint8_t > NimBLEAdvertisementData::getPayload ( ) const

Retrieve the payload that is to be advertised.

Returns
The payload of the advertisement data.

◆ removeData()

bool NimBLEAdvertisementData::removeData ( uint8_t  type)

Remove data from the advertisement data.

Parameters
[in]typeThe type of data to remove.
Returns
True if successful, false if the data was not found.

◆ removeServiceUUID() [1/2]

bool NimBLEAdvertisementData::removeServiceUUID ( const char *  serviceUUID)

Remove a service UUID from the advertisement.

Parameters
[in]serviceUUIDThe UUID of the service to remove.
Returns
True if successful or uuid not found, false if uuid error or data could not be reset.

◆ removeServiceUUID() [2/2]

bool NimBLEAdvertisementData::removeServiceUUID ( const NimBLEUUID serviceUUID)

Remove a service UUID from the advertisement.

Parameters
[in]serviceUUIDThe UUID of the service to remove.
Returns
True if successful or uuid not found, false if uuid error or data could not be reset.

◆ setAppearance()

bool NimBLEAdvertisementData::setAppearance ( uint16_t  appearance)

Set the appearance.

Parameters
[in]appearanceThe appearance code value.
Returns
True if successful.

If the appearance value is 0 then it will be removed from the advertisement if set previously.

◆ setCompleteServices()

bool NimBLEAdvertisementData::setCompleteServices ( const NimBLEUUID uuid)

Set a single service to advertise as a complete list of services.

Parameters
[in]uuidThe service to advertise.
Returns
True if successful.

◆ setCompleteServices16()

bool NimBLEAdvertisementData::setCompleteServices16 ( const std::vector< NimBLEUUID > &  uuids)

Set the complete list of 16 bit services to advertise.

Parameters
[in]uuidsA vector of 16 bit UUID's to advertise.
Returns
True if successful.

◆ setCompleteServices32()

bool NimBLEAdvertisementData::setCompleteServices32 ( const std::vector< NimBLEUUID > &  uuids)

Set the complete list of 32 bit services to advertise.

Parameters
[in]uuidsA vector of 32 bit UUID's to advertise.
Returns
True if successful.

◆ setFlags()

bool NimBLEAdvertisementData::setFlags ( uint8_t  flag)

Set the advertisement flags.

Parameters
[in]flagThe flags to be set in the advertisement.
  • BLE_HS_ADV_F_DISC_LTD
  • BLE_HS_ADV_F_DISC_GEN
  • BLE_HS_ADV_F_BREDR_UNSUP - must always use with NimBLE A flag value of 0 will remove the flags from the advertisement.

◆ setManufacturerData() [1/3]

bool NimBLEAdvertisementData::setManufacturerData ( const std::string &  data)

Set manufacturer specific data.

Parameters
[in]dataThe manufacturer data to advertise.
Returns
True if successful.

◆ setManufacturerData() [2/3]

bool NimBLEAdvertisementData::setManufacturerData ( const std::vector< uint8_t > &  data)

Set manufacturer specific data.

Parameters
[in]dataThe manufacturer data to advertise.
Returns
True if successful.

◆ setManufacturerData() [3/3]

bool NimBLEAdvertisementData::setManufacturerData ( const uint8_t *  data,
size_t  length 
)

Set manufacturer specific data.

Parameters
[in]dataThe manufacturer data to advertise.
[in]lengthThe length of the data.
Returns
True if successful.

◆ setName()

bool NimBLEAdvertisementData::setName ( const std::string &  name,
bool  isComplete = true 
)

Set the complete name of this device.

Parameters
[in]nameThe name to advertise.
[in]isCompleteIf true the name is complete, which will set the data type accordingly.

If the name is longer than 29 characters it will be truncated. and the data type will be set to incomplete name.

Returns
True if successful.

◆ setPartialServices()

bool NimBLEAdvertisementData::setPartialServices ( const NimBLEUUID uuid)

Set a single service to advertise as a partial list of services.

Parameters
[in]uuidThe service to advertise.
Returns
True if successful.

◆ setPartialServices16()

bool NimBLEAdvertisementData::setPartialServices16 ( const std::vector< NimBLEUUID > &  uuids)

Set the partial list of services to advertise.

Parameters
[in]uuidsA vector of 16 bit UUID's to advertise.
Returns
True if successful.

◆ setPartialServices32()

bool NimBLEAdvertisementData::setPartialServices32 ( const std::vector< NimBLEUUID > &  uuids)

Set the partial list of services to advertise.

Parameters
[in]uuidsA vector of 32 bit UUID's to advertise.
Returns
True if successful.

◆ setPreferredParams()

bool NimBLEAdvertisementData::setPreferredParams ( uint16_t  minInterval,
uint16_t  maxInterval 
)

Set the preferred min and max connection intervals to advertise.

Parameters
[in]minIntervalThe minimum preferred connection interval.
[in]maxIntervalThe Maximum preferred connection interval.

Range = 0x0006(7.5ms) to 0x0C80(4000ms), values not within the range will be limited to this range.

Returns
True if successful.

◆ setServiceData() [1/3]

bool NimBLEAdvertisementData::setServiceData ( const NimBLEUUID uuid,
const std::string &  data 
)

Set the service data (UUID + data)

Parameters
[in]uuidThe UUID to set with the service data.
[in]dataThe data to be associated with the service data advertised.
Returns
True if the service data was set successfully.
Note
If data length is 0 the service data will not be advertised.

◆ setServiceData() [2/3]

bool NimBLEAdvertisementData::setServiceData ( const NimBLEUUID uuid,
const std::vector< uint8_t > &  data 
)

Set the service data advertised for the UUID.

Parameters
[in]uuidThe UUID the service data belongs to.
[in]dataThe data to advertise.
Returns
True if the service data was set successfully.
Note
If data length is 0 the service data will not be advertised.

◆ setServiceData() [3/3]

bool NimBLEAdvertisementData::setServiceData ( const NimBLEUUID uuid,
const uint8_t *  data,
size_t  length 
)

Set the service data advertised for the UUID.

Parameters
[in]uuidThe UUID the service data belongs to.
[in]dataThe data to advertise.
[in]lengthThe length of the data.
Note
If data length is 0 the service data will not be advertised.
Returns
True if successful, false if data length is too long or could not be set.

◆ setShortName()

bool NimBLEAdvertisementData::setShortName ( const std::string &  name)

Set the short name.

Parameters
[in]nameThe short name of the device.
Returns
True if successful.

◆ setURI()

bool NimBLEAdvertisementData::setURI ( const std::string &  uri)

Set the URI to advertise.

Parameters
[in]uriThe uri to advertise.
Returns
True if successful.

◆ toString()

std::string NimBLEAdvertisementData::toString ( ) const

Get the string representation of the advertisement data.

Returns
The string representation of the advertisement data.