esp-nimble-cpp  1.4.1
NimBLEAddress Class Reference

A BLE device address. More...

Public Member Functions

 NimBLEAddress ()
 Create a blank address, i.e. 00:00:00:00:00:00, type 0.
 
 NimBLEAddress (ble_addr_t address)
 Create an address from the native NimBLE representation. More...
 
 NimBLEAddress (uint8_t address[6], uint8_t type=BLE_ADDR_PUBLIC)
 Constructor for compatibility with bluedroid esp library using native ESP representation. More...
 
 NimBLEAddress (const std::string &stringAddress, uint8_t type=BLE_ADDR_PUBLIC)
 Create an address from a hex string. More...
 
 NimBLEAddress (const uint64_t &address, uint8_t type=BLE_ADDR_PUBLIC)
 Constructor for address using a hex value.
Use the same byte order, so use 0xa4c1385def16 for "a4:c1:38:5d:ef:16". More...
 
bool equals (const NimBLEAddress &otherAddress) const
 Determine if this address equals another. More...
 
const uint8_t * getNative () const
 Get the native representation of the address. More...
 
std::string toString () const
 Convert a BLE address to a string. More...
 
uint8_t getType () const
 Get the address type. More...
 
bool operator== (const NimBLEAddress &rhs) const
 Convenience operator to check if this address is equal to another.
 
bool operator!= (const NimBLEAddress &rhs) const
 Convenience operator to check if this address is not equal to another.
 
 operator std::string () const
 Convienience operator to convert this address to string representation. More...
 
 operator uint64_t () const
 Convenience operator to convert the native address representation to uint_64.
 

Detailed Description

A BLE device address.

Every BLE device has a unique address which can be used to identify it and form connections.

Constructor & Destructor Documentation

◆ NimBLEAddress() [1/4]

NimBLEAddress::NimBLEAddress ( ble_addr_t  address)

Create an address from the native NimBLE representation.

Parameters
[in]addressThe native NimBLE address.

◆ NimBLEAddress() [2/4]

NimBLEAddress::NimBLEAddress ( uint8_t  address[6],
uint8_t  type = BLE_ADDR_PUBLIC 
)

Constructor for compatibility with bluedroid esp library using native ESP representation.

Parameters
[in]addressA uint8_t[6] or esp_bd_addr_t containing the address.
[in]typeThe type of the address.

◆ NimBLEAddress() [3/4]

NimBLEAddress::NimBLEAddress ( const std::string &  stringAddress,
uint8_t  type = BLE_ADDR_PUBLIC 
)

Create an address from a hex string.

A hex string is of the format:

00:00:00:00:00:00

which is 17 characters in length.

Parameters
[in]stringAddressThe hex string representation of the address.
[in]typeThe type of the address.

◆ NimBLEAddress() [4/4]

NimBLEAddress::NimBLEAddress ( const uint64_t &  address,
uint8_t  type = BLE_ADDR_PUBLIC 
)

Constructor for address using a hex value.
Use the same byte order, so use 0xa4c1385def16 for "a4:c1:38:5d:ef:16".

Parameters
[in]addressuint64_t containing the address.
[in]typeThe type of the address.

Member Function Documentation

◆ equals()

bool NimBLEAddress::equals ( const NimBLEAddress otherAddress) const

Determine if this address equals another.

Parameters
[in]otherAddressThe other address to compare against.
Returns
True if the addresses are equal.

◆ getNative()

const uint8_t * NimBLEAddress::getNative ( ) const

Get the native representation of the address.

Returns
a pointer to the uint8_t[6] array of the address.

◆ getType()

uint8_t NimBLEAddress::getType ( ) const

Get the address type.

Returns
The address type.

◆ operator std::string()

NimBLEAddress::operator std::string ( ) const

Convienience operator to convert this address to string representation.

This allows passing NimBLEAddress to functions that accept std::string and/or or it's methods as a parameter.

◆ toString()

std::string NimBLEAddress::toString ( ) const

Convert a BLE address to a string.

A string representation of an address is in the format:

xx:xx:xx:xx:xx:xx
Returns
The string representation of the address.
Deprecated:
Use std::string() operator instead.