esp-nimble-cpp 2.0.2
|
A model of a BLE client. More...
#include <NimBLEClient.h>
Public Member Functions | |
bool | connect (const NimBLEAdvertisedDevice *device, bool deleteAttributes=true, bool asyncConnect=false, bool exchangeMTU=true) |
Connect to an advertising device. | |
bool | connect (const NimBLEAddress &address, bool deleteAttributes=true, bool asyncConnect=false, bool exchangeMTU=true) |
Connect to a BLE Server by address. | |
bool | connect (bool deleteAttributes=true, bool asyncConnect=false, bool exchangeMTU=true) |
Connect to the BLE Server using the address of the last connected device, or the address passed to the constructor. | |
bool | disconnect (uint8_t reason=BLE_ERR_REM_USER_CONN_TERM) |
Disconnect from the peer. | |
bool | cancelConnect () const |
Cancel an ongoing connection attempt. | |
void | setSelfDelete (bool deleteOnDisconnect, bool deleteOnConnectFail) |
Set or unset a flag to delete this client when disconnected or connection failed. | |
NimBLEAddress | getPeerAddress () const |
Retrieve the address of the peer. | |
bool | setPeerAddress (const NimBLEAddress &address) |
Set the peer address. | |
int | getRssi () const |
Ask the BLE server for the RSSI value. | |
bool | isConnected () const |
Are we connected to a server? | |
void | setClientCallbacks (NimBLEClientCallbacks *pClientCallbacks, bool deleteCallbacks=true) |
Set the callbacks that will be invoked when events are received. | |
std::string | toString () const |
Return a string representation of this client. | |
uint16_t | getConnHandle () const |
Get the connection handle for this client. | |
uint16_t | getMTU () const |
Get the current mtu of this connection. | |
bool | exchangeMTU () |
Begin the MTU exchange process with the server. | |
bool | secureConnection (bool async=false) const |
Initiate a secure connection (pair/bond) with the server. Called automatically when a characteristic or descriptor requires encryption or authentication to access it. | |
void | setConnectTimeout (uint32_t timeout) |
Set the timeout to wait for connection attempt to complete. | |
bool | setDataLen (uint16_t txOctets) |
Request an update of the data packet length. | |
bool | discoverAttributes () |
Retrieves the full database of attributes that the peripheral has available. | |
NimBLEConnInfo | getConnInfo () const |
Get detailed information about the current peer connection. | |
int | getLastError () const |
Get the last error code reported by the NimBLE host. | |
bool | updateConnParams (uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout) |
Update the connection parameters: | |
void | setConnectionParams (uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout, uint16_t scanInterval=16, uint16_t scanWindow=16) |
Set the connection parameters to use when connecting to a server. | |
const std::vector< NimBLERemoteService * > & | getServices (bool refresh=false) |
Get a pointer to the vector of found services. | |
std::vector< NimBLERemoteService * >::iterator | begin () |
Get iterator to the beginning of the vector of remote service pointers. | |
std::vector< NimBLERemoteService * >::iterator | end () |
Get iterator to the end of the vector of remote service pointers. | |
NimBLERemoteCharacteristic * | getCharacteristic (uint16_t handle) |
Get the remote characteristic with the specified handle. | |
NimBLERemoteService * | getService (const char *uuid) |
Get the service BLE Remote Service instance corresponding to the uuid. | |
NimBLERemoteService * | getService (const NimBLEUUID &uuid) |
Get the service object corresponding to the uuid. | |
void | deleteServices () |
Delete all service objects created by this client and clear the vector. | |
size_t | deleteService (const NimBLEUUID &uuid) |
Delete a service by UUID from the local database to free resources. | |
NimBLEAttValue | getValue (const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID) |
Get the value of a specific characteristic associated with a specific service. | |
bool | setValue (const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID, const NimBLEAttValue &value, bool response=false) |
Set the value of a specific characteristic associated with a specific service. | |
void | setConnectPhy (uint8_t phyMask) |
Set the PHY types to use when connecting to a server. | |
bool | updatePhy (uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions=0) |
Request a change to the PHY used for this peer connection. | |
bool | getPhy (uint8_t *txPhy, uint8_t *rxPhy) |
Get the PHY used for this peer connection. | |
Config | getConfig () const |
Get a copy of the clients configuration. | |
void | setConfig (Config config) |
Set the client configuration options. | |
A model of a BLE client.
std::vector< NimBLERemoteService * >::iterator NimBLEClient::begin | ( | ) |
Get iterator to the beginning of the vector of remote service pointers.
bool NimBLEClient::cancelConnect | ( | ) | const |
Cancel an ongoing connection attempt.
bool NimBLEClient::connect | ( | bool | deleteAttributes = true , |
bool | asyncConnect = false , |
||
bool | exchangeMTU = true |
||
) |
Connect to the BLE Server using the address of the last connected device, or the address
passed to the constructor.
[in] | deleteAttributes | If true this will delete any attribute objects this client may already have created when last connected. |
[in] | asyncConnect | If true, the connection will be made asynchronously and this function will return immediately. If false, this function will block until the connection is established or the connection attempt times out. |
[in] | exchangeMTU | If true, the client will attempt to exchange MTU with the server after connection. If false, the client will use the default MTU size and the application will need to call exchangeMTU() later. |
bool NimBLEClient::connect | ( | const NimBLEAddress & | address, |
bool | deleteAttributes = true , |
||
bool | asyncConnect = false , |
||
bool | exchangeMTU = true |
||
) |
Connect to a BLE Server by address.
[in] | address | The address of the server. |
[in] | deleteAttributes | If true this will delete any attribute objects this client may already have created when last connected. |
[in] | asyncConnect | If true, the connection will be made asynchronously and this function will return immediately. If false, this function will block until the connection is established or the connection attempt times out. |
[in] | exchangeMTU | If true, the client will attempt to exchange MTU with the server after connection. If false, the client will use the default MTU size and the application will need to call exchangeMTU() later. |
bool NimBLEClient::connect | ( | const NimBLEAdvertisedDevice * | device, |
bool | deleteAttributes = true , |
||
bool | asyncConnect = false , |
||
bool | exchangeMTU = true |
||
) |
Connect to an advertising device.
[in] | device | The device to connect to. |
[in] | deleteAttributes | If true this will delete any attribute objects this client may already have created when last connected. |
[in] | asyncConnect | If true, the connection will be made asynchronously and this function will return immediately. If false, this function will block until the connection is established or the connection attempt times out. |
[in] | exchangeMTU | If true, the client will attempt to exchange MTU with the server after connection. If false, the client will use the default MTU size and the application will need to call exchangeMTU() later. |
size_t NimBLEClient::deleteService | ( | const NimBLEUUID & | uuid | ) |
Delete a service by UUID from the local database to free resources.
[in] | uuid | The UUID of the service to be deleted. |
bool NimBLEClient::disconnect | ( | uint8_t | reason = BLE_ERR_REM_USER_CONN_TERM | ) |
Disconnect from the peer.
bool NimBLEClient::discoverAttributes | ( | ) |
Retrieves the full database of attributes that the peripheral has available.
std::vector< NimBLERemoteService * >::iterator NimBLEClient::end | ( | ) |
Get iterator to the end of the vector of remote service pointers.
bool NimBLEClient::exchangeMTU | ( | ) |
Begin the MTU exchange process with the server.
NimBLERemoteCharacteristic * NimBLEClient::getCharacteristic | ( | uint16_t | handle | ) |
Get the remote characteristic with the specified handle.
[in] | handle | The handle of the desired characteristic. |
NimBLEClient::Config NimBLEClient::getConfig | ( | ) | const |
Get a copy of the clients configuration.
uint16_t NimBLEClient::getConnHandle | ( | ) | const |
Get the connection handle for this client.
NimBLEConnInfo NimBLEClient::getConnInfo | ( | ) | const |
Get detailed information about the current peer connection.
int NimBLEClient::getLastError | ( | ) | const |
Get the last error code reported by the NimBLE host.
uint16_t NimBLEClient::getMTU | ( | ) | const |
Get the current mtu of this connection.
NimBLEAddress NimBLEClient::getPeerAddress | ( | ) | const |
Retrieve the address of the peer.
bool NimBLEClient::getPhy | ( | uint8_t * | txPhy, |
uint8_t * | rxPhy | ||
) |
Get the PHY used for this peer connection.
[out] | txPhy | The TX PHY. |
[out] | rxPhy | The RX PHY. |
int NimBLEClient::getRssi | ( | ) | const |
Ask the BLE server for the RSSI value.
NimBLERemoteService * NimBLEClient::getService | ( | const char * | uuid | ) |
Get the service BLE Remote Service instance corresponding to the uuid.
[in] | uuid | The UUID of the service being sought. |
NimBLERemoteService * NimBLEClient::getService | ( | const NimBLEUUID & | uuid | ) |
Get the service object corresponding to the uuid.
[in] | uuid | The UUID of the service being sought. |
const std::vector< NimBLERemoteService * > & NimBLEClient::getServices | ( | bool | refresh = false | ) |
Get a pointer to the vector of found services.
[in] | refresh | If true the current services vector will be cleared and all services will be retrieved from the peripheral. If false the vector will be returned with the currently stored services. |
NimBLEAttValue NimBLEClient::getValue | ( | const NimBLEUUID & | serviceUUID, |
const NimBLEUUID & | characteristicUUID | ||
) |
Get the value of a specific characteristic associated with a specific service.
[in] | serviceUUID | The service that owns the characteristic. |
[in] | characteristicUUID | The characteristic whose value we wish to read. |
bool NimBLEClient::isConnected | ( | ) | const |
Are we connected to a server?
bool NimBLEClient::secureConnection | ( | bool | async = false | ) | const |
Initiate a secure connection (pair/bond) with the server.
Called automatically when a characteristic or descriptor requires encryption or authentication to access it.
[in] | async | If true, the connection will be secured asynchronously and this function will return immediately. If false, this function will block until the connection is secured or the client disconnects. |
If async=false, this function will block and should not be used in a callback.
void NimBLEClient::setClientCallbacks | ( | NimBLEClientCallbacks * | pClientCallbacks, |
bool | deleteCallbacks = true |
||
) |
Set the callbacks that will be invoked when events are received.
[in] | pClientCallbacks | A pointer to a class to receive the event callbacks. |
[in] | deleteCallbacks | If true this will delete the callback class sent when the client is destructed. |
void NimBLEClient::setConfig | ( | NimBLEClient::Config | config | ) |
Set the client configuration options.
[in] | config | The config options instance to set the client configuration to. |
void NimBLEClient::setConnectionParams | ( | uint16_t | minInterval, |
uint16_t | maxInterval, | ||
uint16_t | latency, | ||
uint16_t | timeout, | ||
uint16_t | scanInterval = 16 , |
||
uint16_t | scanWindow = 16 |
||
) |
Set the connection parameters to use when connecting to a server.
[in] | minInterval | The minimum connection interval in 1.25ms units. |
[in] | maxInterval | The maximum connection interval in 1.25ms units. |
[in] | latency | The number of packets allowed to skip (extends max interval). |
[in] | timeout | The timeout time in 10ms units before disconnecting. |
[in] | scanInterval | The scan interval to use when attempting to connect in 0.625ms units. |
[in] | scanWindow | The scan window to use when attempting to connect in 0.625ms units. |
void NimBLEClient::setConnectPhy | ( | uint8_t | mask | ) |
Set the PHY types to use when connecting to a server.
[in] | mask | A bitmask indicating what PHYS to connect with. The available bits are:
|
void NimBLEClient::setConnectTimeout | ( | uint32_t | time | ) |
Set the timeout to wait for connection attempt to complete.
[in] | time | The number of milliseconds before timeout, default is 30 seconds. |
bool NimBLEClient::setDataLen | ( | uint16_t | txOctets | ) |
Request an update of the data packet length.
Can only be used after a connection has been established.
Sends a data length update request to the server the client is connected to. The Data Length Extension (DLE) allows to increase the Data Channel Payload from 27 bytes to up to 251 bytes. The server needs to support the Bluetooth 4.2 specifications, to be capable of DLE.
[in] | txOctets | The preferred number of payload octets to use (Range 0x001B-0x00FB). |
bool NimBLEClient::setPeerAddress | ( | const NimBLEAddress & | address | ) |
Set the peer address.
[in] | address | The address of the peer that this client is connected or should connect to. |
void NimBLEClient::setSelfDelete | ( | bool | deleteOnDisconnect, |
bool | deleteOnConnectFail | ||
) |
Set or unset a flag to delete this client when disconnected or connection failed.
[in] | deleteOnDisconnect | Set the client to self delete when disconnected. |
[in] | deleteOnConnectFail | Set the client to self delete when a connection attempt fails. |
bool NimBLEClient::setValue | ( | const NimBLEUUID & | serviceUUID, |
const NimBLEUUID & | characteristicUUID, | ||
const NimBLEAttValue & | value, | ||
bool | response = false |
||
) |
Set the value of a specific characteristic associated with a specific service.
[in] | serviceUUID | The service that owns the characteristic. |
[in] | characteristicUUID | The characteristic whose value we wish to write. |
[in] | value | The value to write to the characteristic. |
[in] | response | If true, uses write with response operation. |
std::string NimBLEClient::toString | ( | ) | const |
Return a string representation of this client.
bool NimBLEClient::updateConnParams | ( | uint16_t | minInterval, |
uint16_t | maxInterval, | ||
uint16_t | latency, | ||
uint16_t | timeout | ||
) |
Update the connection parameters:
[in] | minInterval | The minimum connection interval in 1.25ms units. |
[in] | maxInterval | The maximum connection interval in 1.25ms units. |
[in] | latency | The number of packets allowed to skip (extends max interval). |
[in] | timeout | The timeout time in 10ms units before disconnecting. |
bool NimBLEClient::updatePhy | ( | uint8_t | txPhyMask, |
uint8_t | rxPhyMask, | ||
uint16_t | phyOptions = 0 |
||
) |
Request a change to the PHY used for this peer connection.
[in] | txPhyMask | TX PHY. Can be mask of following:
|
[in] | rxPhyMask | RX PHY. Can be mask of following:
|
phyOptions | Additional PHY options. Valid values are:
|