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

A representation of a BLE advertised device found by a scan. More...

#include <NimBLEAdvertisedDevice.h>

Public Member Functions

uint8_t getAdvType () const
 Get the advertisement type.
 
uint8_t getAdvFlags () const
 Get the advertisement flags.
 
uint16_t getAppearance () const
 Get the appearance.
 
uint16_t getAdvInterval () const
 Get the advertisement interval.
 
uint16_t getMinInterval () const
 Get the preferred min connection interval.
 
uint16_t getMaxInterval () const
 Get the preferred max connection interval.
 
uint8_t getManufacturerDataCount () const
 Get the count of manufacturer data sets.
 
const NimBLEAddressgetAddress () const
 Get the address of the advertising device.
 
std::string getManufacturerData (uint8_t index=0) const
 Get the manufacturer data.
 
std::string getURI () const
 Get the URI from the advertisement.
 
std::string getPayloadByType (uint16_t type, uint8_t index=0) const
 Get the data from any type available in the advertisement.
 
std::string getName () const
 Get the advertised name.
 
int8_t getRSSI () const
 Get the RSSI.
 
NimBLEScangetScan () const
 Get the scan object that created this advertised device.
 
uint8_t getServiceDataCount () const
 Get the count of advertised service data UUIDS.
 
std::string getServiceData (uint8_t index=0) const
 Get the service data.
 
std::string getServiceData (const NimBLEUUID &uuid) const
 Get the service data.
 
NimBLEUUID getServiceDataUUID (uint8_t index=0) const
 Get the UUID of the service data at the index.
 
NimBLEUUID getServiceUUID (uint8_t index=0) const
 Get the Service UUID.
 
uint8_t getServiceUUIDCount () const
 Get the number of services advertised.
 
NimBLEAddress getTargetAddress (uint8_t index=0) const
 Get the target address at the index.
 
uint8_t getTargetAddressCount () const
 Get the number of target addresses.
 
int8_t getTXPower () const
 Get the TX Power.
 
uint8_t getAdvLength () const
 Get the length of the advertisement data in the payload.
 
uint8_t getAddressType () const
 Get the advertised device address type.
 
bool isAdvertisingService (const NimBLEUUID &uuid) const
 Check advertised services for existence of the required UUID.
 
bool haveAppearance () const
 Does this advertisement have an appearance value?
 
bool haveManufacturerData () const
 Does this advertisement have manufacturer data?
 
bool haveName () const
 Does this advertisement have a name value?
 
bool haveServiceData () const
 Does this advertisement have a service data value?
 
bool haveServiceUUID () const
 Does this advertisement have a service UUID value?
 
bool haveTXPower () const
 Does this advertisement have a transmission power value?
 
bool haveConnParams () const
 Does this advertisement have preferred connection parameters?
 
bool haveAdvInterval () const
 Does this advertisement have have the advertising interval?
 
bool haveTargetAddress () const
 Does the advertisement contain a target address?
 
bool haveURI () const
 Does this advertisement have a URI?
 
bool haveType (uint16_t type) const
 Does this advertisement have a adv type type?
 
std::string toString () const
 Create a string representation of this device.
 
bool isConnectable () const
 Check if this device is advertising as connectable.
 
bool isScannable () const
 Check if this device is advertising as scannable.
 
bool isLegacyAdvertisement () const
 Check if this advertisement is a legacy or extended type.
 
uint8_t getSetId () const
 Get the set ID of the extended advertisement.
 
uint8_t getPrimaryPhy () const
 Get the primary PHY used by this advertisement.
 
uint8_t getSecondaryPhy () const
 Get the primary PHY used by this advertisement.
 
uint16_t getPeriodicInterval () const
 Get the periodic interval of the advertisement.
 
const std::vector< uint8_t > & getPayload () const
 Get the payload advertised by the device.
 
const std::vector< uint8_t >::const_iterator begin () const
 Get the begin iterator for the payload.
 
const std::vector< uint8_t >::const_iterator end () const
 Get the end iterator for the payload.
 
template<typename T >
getManufacturerData (bool skipSizeCheck=false) const
 A template to convert the service data to <type>.
 
template<typename T >
getServiceData (uint8_t index=0, bool skipSizeCheck=false) const
 A template to convert the service data to <type>.
 
template<typename T >
getServiceData (const NimBLEUUID &uuid, bool skipSizeCheck=false) const
 A template to convert the service data to <type>.
 

Detailed Description

A representation of a BLE advertised device found by a scan.

When we perform a BLE scan, the result will be a set of devices that are advertising. This class provides a model of a detected device.

Member Function Documentation

◆ begin()

const std::vector< uint8_t >::const_iterator NimBLEAdvertisedDevice::begin ( ) const

Get the begin iterator for the payload.

Returns
A read only iterator pointing to the first byte in the payload.

◆ end()

const std::vector< uint8_t >::const_iterator NimBLEAdvertisedDevice::end ( ) const

Get the end iterator for the payload.

Returns
A read only iterator pointing to one past the last byte of the payload.

◆ getAddress()

const NimBLEAddress & NimBLEAdvertisedDevice::getAddress ( ) const

Get the address of the advertising device.

Returns
The address of the advertised device.

◆ getAddressType()

uint8_t NimBLEAdvertisedDevice::getAddressType ( ) const

Get the advertised device address type.

Returns
The device address type:
  • BLE_ADDR_PUBLIC (0x00)
  • BLE_ADDR_RANDOM (0x01)
  • BLE_ADDR_PUBLIC_ID (0x02)
  • BLE_ADDR_RANDOM_ID (0x03)

◆ getAdvFlags()

uint8_t NimBLEAdvertisedDevice::getAdvFlags ( ) const

Get the advertisement flags.

Returns
The advertisement flags, a bitmask of: BLE_HS_ADV_F_DISC_LTD (0x01) - limited discoverability BLE_HS_ADV_F_DISC_GEN (0x02) - general discoverability BLE_HS_ADV_F_BREDR_UNSUP - BR/EDR not supported

◆ getAdvInterval()

uint16_t NimBLEAdvertisedDevice::getAdvInterval ( ) const

Get the advertisement interval.

Returns
The advertisement interval in 0.625ms units.

◆ getAdvLength()

uint8_t NimBLEAdvertisedDevice::getAdvLength ( ) const

Get the length of the advertisement data in the payload.

Returns
The number of bytes in the payload that is from the advertisement.

◆ getAdvType()

uint8_t NimBLEAdvertisedDevice::getAdvType ( ) const

Get the advertisement type.

Returns
The advertising type the device is reporting:
  • BLE_HCI_ADV_TYPE_ADV_IND (0) - indirect advertising
  • BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD (1) - direct advertising - high duty cycle
  • BLE_HCI_ADV_TYPE_ADV_SCAN_IND (2) - indirect scan response
  • BLE_HCI_ADV_TYPE_ADV_NONCONN_IND (3) - indirect advertising - not connectable
  • BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD (4) - direct advertising - low duty cycle

◆ getAppearance()

uint16_t NimBLEAdvertisedDevice::getAppearance ( ) const

Get the appearance.

A BLE device can declare its own appearance. The appearance is how it would like to be shown to an end user typically in the form of an icon.

Returns
The appearance of the advertised device.

◆ getManufacturerData() [1/2]

template<typename T >
T NimBLEAdvertisedDevice::getManufacturerData ( bool  skipSizeCheck = false) const
inline

A template to convert the service data to <type>.

Template Parameters
TThe type to convert the data to.
Parameters
[in]skipSizeCheckIf true it will skip checking if the data size is less than sizeof(<type>).
Returns
The data converted to <type> or NULL if skipSizeCheck is false and the data is less than sizeof(<type>).

Use: getManufacturerData<type>(skipSizeCheck);

◆ getManufacturerData() [2/2]

std::string NimBLEAdvertisedDevice::getManufacturerData ( uint8_t  index = 0) const

Get the manufacturer data.

Parameters
[in]indexThe index of the of the manufacturer data set to get.
Returns
The manufacturer data.

◆ getManufacturerDataCount()

uint8_t NimBLEAdvertisedDevice::getManufacturerDataCount ( ) const

Get the count of manufacturer data sets.

Returns
The number of manufacturer data sets.

◆ getMaxInterval()

uint16_t NimBLEAdvertisedDevice::getMaxInterval ( ) const

Get the preferred max connection interval.

Returns
The preferred max connection interval in 1.25ms units.

◆ getMinInterval()

uint16_t NimBLEAdvertisedDevice::getMinInterval ( ) const

Get the preferred min connection interval.

Returns
The preferred min connection interval in 1.25ms units.

◆ getName()

std::string NimBLEAdvertisedDevice::getName ( ) const

Get the advertised name.

Returns
The name of the advertised device.

◆ getPayload()

const std::vector< uint8_t > & NimBLEAdvertisedDevice::getPayload ( ) const

Get the payload advertised by the device.

Returns
The advertisement payload.

◆ getPayloadByType()

std::string NimBLEAdvertisedDevice::getPayloadByType ( uint16_t  type,
uint8_t  index = 0 
) const

Get the data from any type available in the advertisement.

Parameters
[in]typeThe advertised data type BLE_HS_ADV_TYPE.
[in]indexThe index of the data type.
Returns
The data available under the type type.

◆ getPeriodicInterval()

uint16_t NimBLEAdvertisedDevice::getPeriodicInterval ( ) const

Get the periodic interval of the advertisement.

Returns
The periodic advertising interval, 0 if not periodic advertising.

◆ getPrimaryPhy()

uint8_t NimBLEAdvertisedDevice::getPrimaryPhy ( ) const

Get the primary PHY used by this advertisement.

Returns
The PHY type, one of:
  • BLE_HCI_LE_PHY_1M
  • BLE_HCI_LE_PHY_CODED

◆ getRSSI()

int8_t NimBLEAdvertisedDevice::getRSSI ( ) const

Get the RSSI.

Returns
The RSSI of the advertised device.

◆ getScan()

NimBLEScan * NimBLEAdvertisedDevice::getScan ( ) const

Get the scan object that created this advertised device.

Returns
The scan object.

◆ getSecondaryPhy()

uint8_t NimBLEAdvertisedDevice::getSecondaryPhy ( ) const

Get the primary PHY used by this advertisement.

Returns
The PHY type, one of:
  • BLE_HCI_LE_PHY_1M
  • BLE_HCI_LE_PHY_2M
  • BLE_HCI_LE_PHY_CODED

◆ getServiceData() [1/4]

std::string NimBLEAdvertisedDevice::getServiceData ( const NimBLEUUID uuid) const

Get the service data.

Parameters
[in]uuidThe uuid of the service data requested.
Returns
The advertised service data or empty string if no data.

◆ getServiceData() [2/4]

template<typename T >
T NimBLEAdvertisedDevice::getServiceData ( const NimBLEUUID uuid,
bool  skipSizeCheck = false 
) const
inline

A template to convert the service data to <type>.

Template Parameters
TThe type to convert the data to.
Parameters
[in]uuidThe uuid of the service data requested.
[in]skipSizeCheckIf true it will skip checking if the data size is less than sizeof(<type>).
Returns
The data converted to <type> or NULL if skipSizeCheck is false and the data is less than sizeof(<type>).

Use: getServiceData<type>(skipSizeCheck);

◆ getServiceData() [3/4]

std::string NimBLEAdvertisedDevice::getServiceData ( uint8_t  index = 0) const

Get the service data.

Parameters
[in]indexThe index of the service data requested.
Returns
The advertised service data or empty string if no data.

◆ getServiceData() [4/4]

template<typename T >
T NimBLEAdvertisedDevice::getServiceData ( uint8_t  index = 0,
bool  skipSizeCheck = false 
) const
inline

A template to convert the service data to <type>.

Template Parameters
TThe type to convert the data to.
Parameters
[in]indexThe vector index of the service data requested.
[in]skipSizeCheckIf true it will skip checking if the data size is less than sizeof(<type>).
Returns
The data converted to <type> or NULL if skipSizeCheck is false and the data is less than sizeof(<type>).

Use: getServiceData<type>(skipSizeCheck);

◆ getServiceDataCount()

uint8_t NimBLEAdvertisedDevice::getServiceDataCount ( ) const

Get the count of advertised service data UUIDS.

Returns
The number of service data UUIDS in the vector.

◆ getServiceDataUUID()

NimBLEUUID NimBLEAdvertisedDevice::getServiceDataUUID ( uint8_t  index = 0) const

Get the UUID of the service data at the index.

Parameters
[in]indexThe index of the service data UUID requested.
Returns
The advertised service data UUID or an empty UUID if not found.

◆ getServiceUUID()

NimBLEUUID NimBLEAdvertisedDevice::getServiceUUID ( uint8_t  index = 0) const

Get the Service UUID.

Parameters
[in]indexThe index of the service UUID requested.
Returns
The Service UUID of the advertised service, or an empty UUID if not found.

◆ getServiceUUIDCount()

uint8_t NimBLEAdvertisedDevice::getServiceUUIDCount ( ) const

Get the number of services advertised.

Returns
The count of services in the advertising packet.

◆ getSetId()

uint8_t NimBLEAdvertisedDevice::getSetId ( ) const

Get the set ID of the extended advertisement.

Returns
The set ID.

◆ getTargetAddress()

NimBLEAddress NimBLEAdvertisedDevice::getTargetAddress ( uint8_t  index = 0) const

Get the target address at the index.

Parameters
[in]indexThe index of the target address.
Returns
The target address.

◆ getTargetAddressCount()

uint8_t NimBLEAdvertisedDevice::getTargetAddressCount ( ) const

Get the number of target addresses.

Returns
The number of addresses.

◆ getTXPower()

int8_t NimBLEAdvertisedDevice::getTXPower ( ) const

Get the TX Power.

Returns
The TX Power of the advertised device.

◆ getURI()

std::string NimBLEAdvertisedDevice::getURI ( ) const

Get the URI from the advertisement.

Returns
The URI data.

◆ haveAdvInterval()

bool NimBLEAdvertisedDevice::haveAdvInterval ( ) const

Does this advertisement have have the advertising interval?

Returns
True if the advertisement interval is present.

◆ haveAppearance()

bool NimBLEAdvertisedDevice::haveAppearance ( ) const

Does this advertisement have an appearance value?

Returns
True if there is an appearance value present.

◆ haveConnParams()

bool NimBLEAdvertisedDevice::haveConnParams ( ) const

Does this advertisement have preferred connection parameters?

Returns
True if connection parameters are present.

◆ haveManufacturerData()

bool NimBLEAdvertisedDevice::haveManufacturerData ( ) const

Does this advertisement have manufacturer data?

Returns
True if there is manufacturer data present.

◆ haveName()

bool NimBLEAdvertisedDevice::haveName ( ) const

Does this advertisement have a name value?

Returns
True if there is a name value present.

◆ haveServiceData()

bool NimBLEAdvertisedDevice::haveServiceData ( ) const

Does this advertisement have a service data value?

Returns
True if there is a service data value present.

◆ haveServiceUUID()

bool NimBLEAdvertisedDevice::haveServiceUUID ( ) const

Does this advertisement have a service UUID value?

Returns
True if there is a service UUID value present.

◆ haveTargetAddress()

bool NimBLEAdvertisedDevice::haveTargetAddress ( ) const

Does the advertisement contain a target address?

Returns
True if an address is present.

◆ haveTXPower()

bool NimBLEAdvertisedDevice::haveTXPower ( ) const

Does this advertisement have a transmission power value?

Returns
True if there is a transmission power value present.

◆ haveType()

bool NimBLEAdvertisedDevice::haveType ( uint16_t  type) const

Does this advertisement have a adv type type?

Returns
True if there is a type present.

◆ haveURI()

bool NimBLEAdvertisedDevice::haveURI ( ) const

Does this advertisement have a URI?

Returns
True if there is a URI present.

◆ isAdvertisingService()

bool NimBLEAdvertisedDevice::isAdvertisingService ( const NimBLEUUID uuid) const

Check advertised services for existence of the required UUID.

Parameters
[in]uuidThe service uuid to look for in the advertisement.
Returns
Return true if service is advertised

◆ isConnectable()

bool NimBLEAdvertisedDevice::isConnectable ( ) const

Check if this device is advertising as connectable.

Returns
True if the device is connectable.

◆ isLegacyAdvertisement()

bool NimBLEAdvertisedDevice::isLegacyAdvertisement ( ) const

Check if this advertisement is a legacy or extended type.

Returns
True if legacy (Bluetooth 4.x), false if extended (bluetooth 5.x).

◆ isScannable()

bool NimBLEAdvertisedDevice::isScannable ( ) const

Check if this device is advertising as scannable.

Returns
True if the device is scannable.

◆ toString()

std::string NimBLEAdvertisedDevice::toString ( ) const

Create a string representation of this device.

Returns
A string representation of this device.