NimBLE-Arduino 1.4.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

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

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

◆ getAddress()

NimBLEAddress NimBLEAdvertisedDevice::getAddress ( )

Get the address of the advertising device.

Returns
The address of the advertised device.

◆ getAddressType()

uint8_t NimBLEAdvertisedDevice::getAddressType ( )

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 ( )

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 ( )

Get the advertisement interval.

Returns
The advertisement interval in 0.625ms units.

◆ getAdvLength()

uint8_t NimBLEAdvertisedDevice::getAdvLength ( )

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 ( )

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 ( )

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)
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)

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 ( )

Get the count of manufacturer data sets.

Returns
The number of manufacturer data sets.

◆ getMaxInterval()

uint16_t NimBLEAdvertisedDevice::getMaxInterval ( )

Get the preferred max connection interval.

Returns
The preferred max connection interval in 1.25ms units.

◆ getMinInterval()

uint16_t NimBLEAdvertisedDevice::getMinInterval ( )

Get the preferred min connection interval.

Returns
The preferred min connection interval in 1.25ms units.

◆ getName()

std::string NimBLEAdvertisedDevice::getName ( )

Get the advertised name.

Returns
The name of the advertised device.

◆ getPayload()

uint8_t * NimBLEAdvertisedDevice::getPayload ( )

Get the payload advertised by the device.

Returns
The advertisement payload.

◆ getPayloadByType()

std::string NimBLEAdvertisedDevice::getPayloadByType ( uint16_t  type)

Get the data from any type available in the advertisement.

Parameters
[in]typeThe advertised data type BLE_HS_ADV_TYPE
Returns
The data available under the type type

◆ getPayloadLength()

size_t NimBLEAdvertisedDevice::getPayloadLength ( )

Get the length of the payload advertised by the device.

Returns
The size of the payload in bytes.

◆ getPeriodicInterval()

uint16_t NimBLEAdvertisedDevice::getPeriodicInterval ( )

Get the periodic interval of the advertisement.

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

◆ getPrimaryPhy()

uint8_t NimBLEAdvertisedDevice::getPrimaryPhy ( )

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()

int NimBLEAdvertisedDevice::getRSSI ( )

Get the RSSI.

Returns
The RSSI of the advertised device.

◆ getScan()

NimBLEScan * NimBLEAdvertisedDevice::getScan ( )

Get the scan object that created this advertised device.

Returns
The scan object.

◆ getSecondaryPhy()

uint8_t NimBLEAdvertisedDevice::getSecondaryPhy ( )

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)

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 
)
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)

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 
)
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 ( )

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)

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)

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 ( )

Get the number of services advertised.

Returns
The count of services in the advertising packet.

◆ getSetId()

uint8_t NimBLEAdvertisedDevice::getSetId ( )

Get the set ID of the extended advertisement.

Returns
The set ID.

◆ getTargetAddress()

NimBLEAddress NimBLEAdvertisedDevice::getTargetAddress ( uint8_t  index = 0)

Get the target address at the index.

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

◆ getTargetAddressCount()

uint8_t NimBLEAdvertisedDevice::getTargetAddressCount ( )

Get the number of target addresses.

Returns
The number of addresses.

◆ getTimestamp()

time_t NimBLEAdvertisedDevice::getTimestamp ( )

Get the timeStamp of when the device last advertised.

Returns
The timeStamp of when the device was last seen.

◆ getTXPower()

int8_t NimBLEAdvertisedDevice::getTXPower ( )

Get the TX Power.

Returns
The TX Power of the advertised device.

◆ getURI()

std::string NimBLEAdvertisedDevice::getURI ( )

Get the URI from the advertisement.

Returns
The URI data.

◆ haveAdvInterval()

bool NimBLEAdvertisedDevice::haveAdvInterval ( )

Does this advertisement have have the advertising interval?

Returns
True if the advertisement interval is present.

◆ haveAppearance()

bool NimBLEAdvertisedDevice::haveAppearance ( )

Does this advertisement have an appearance value?

Returns
True if there is an appearance value present.

◆ haveConnParams()

bool NimBLEAdvertisedDevice::haveConnParams ( )

Does this advertisement have preferred connection parameters?

Returns
True if connection parameters are present.

◆ haveManufacturerData()

bool NimBLEAdvertisedDevice::haveManufacturerData ( )

Does this advertisement have manufacturer data?

Returns
True if there is manufacturer data present.

◆ haveName()

bool NimBLEAdvertisedDevice::haveName ( )

Does this advertisement have a name value?

Returns
True if there is a name value present.

◆ haveRSSI()

bool NimBLEAdvertisedDevice::haveRSSI ( )

Does this advertisement have a signal strength value?

Returns
True if there is a signal strength value present.

◆ haveServiceData()

bool NimBLEAdvertisedDevice::haveServiceData ( )

Does this advertisement have a service data value?

Returns
True if there is a service data value present.

◆ haveServiceUUID()

bool NimBLEAdvertisedDevice::haveServiceUUID ( )

Does this advertisement have a service UUID value?

Returns
True if there is a service UUID value present.

◆ haveTargetAddress()

bool NimBLEAdvertisedDevice::haveTargetAddress ( )

Does the advertisement contain a target address?

Returns
True if an address is present.

◆ haveTXPower()

bool NimBLEAdvertisedDevice::haveTXPower ( )

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)

Does this advertisement have a adv type type?

Returns
True if there is a type present.

◆ haveURI()

bool NimBLEAdvertisedDevice::haveURI ( )

Does this advertisement have a URI?

Returns
True if there is a URI present.

◆ isAdvertisingService()

bool NimBLEAdvertisedDevice::isAdvertisingService ( const NimBLEUUID uuid)

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 ( )

Check if this device is advertising as connectable.

Returns
True if the device is connectable.

◆ isLegacyAdvertisement()

bool NimBLEAdvertisedDevice::isLegacyAdvertisement ( )

Check if this advertisement is a legacy or extended type.

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

◆ toString()

std::string NimBLEAdvertisedDevice::toString ( )

Create a string representation of this device.

Returns
A string representation of this device.