14 #ifndef MAIN_NIMBLECLIENT_H_
15 #define MAIN_NIMBLECLIENT_H_
17 #include "sdkconfig.h"
18 #if defined(CONFIG_BT_ENABLED)
21 #if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
23 #include "NimBLEAddress.h"
24 #include "NimBLEUUID.h"
25 #include "NimBLEUtils.h"
26 #include "NimBLEConnInfo.h"
27 #include "NimBLEAdvertisedDevice.h"
28 #include "NimBLERemoteService.h"
45 bool connect(
bool deleteAttibutes =
true);
46 int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
50 std::vector<NimBLERemoteService*>*
getServices(
bool refresh =
false);
51 std::vector<NimBLERemoteService*>::iterator
begin();
52 std::vector<NimBLERemoteService*>::iterator
end();
59 const std::string &value,
bool response =
false);
63 bool deleteCallbacks =
true);
70 uint16_t latency, uint16_t timeout,
71 uint16_t scanInterval=16, uint16_t scanWindow=16);
73 uint16_t latency, uint16_t timeout);
84 static int handleGapEvent(
struct ble_gap_event *event,
void *arg);
85 static int serviceDiscoveredCB(uint16_t conn_handle,
86 const struct ble_gatt_error *error,
87 const struct ble_gatt_svc *service,
89 static void dcTimerCb(ble_npl_event *event);
90 bool retrieveServices(
const NimBLEUUID *uuid_filter =
nullptr);
94 bool m_connEstablished;
95 bool m_deleteCallbacks;
96 int32_t m_connectTimeout;
98 ble_task_data_t* m_pTaskData;
99 ble_npl_callout m_dcTimer;
101 std::vector<NimBLERemoteService*> m_servicesVector;
105 ble_gap_conn_params m_pConnParams;
A BLE device address.
Definition: NimBLEAddress.h:34
A representation of a BLE advertised device found by a scan.
Definition: NimBLEAdvertisedDevice.h:40
Callbacks associated with a BLE client.
Definition: NimBLEClient.h:113
virtual void onDisconnect(NimBLEClient *pClient)
Called when disconnected from the server.
Definition: NimBLEClient.cpp:1143
virtual void onAuthenticationComplete(ble_gap_conn_desc *desc)
Called when the pairing procedure is complete.
Definition: NimBLEClient.cpp:1165
virtual bool onConnParamsUpdateRequest(NimBLEClient *pClient, const ble_gap_upd_params *params)
Called when server requests to update the connection parameters.
Definition: NimBLEClient.cpp:1147
virtual void onConnect(NimBLEClient *pClient)
Called after client connects.
Definition: NimBLEClient.cpp:1139
virtual uint32_t onPassKeyRequest()
Called when server requests a passkey for pairing.
Definition: NimBLEClient.cpp:1152
virtual bool onConfirmPIN(uint32_t pin)
Called when using numeric comparision for pairing.
Definition: NimBLEClient.cpp:1168
A model of a BLE client.
Definition: NimBLEClient.h:41
NimBLEAddress getPeerAddress()
Retrieve the address of the peer.
Definition: NimBLEClient.cpp:478
bool setValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID, const std::string &value, bool response=false)
Set the value of a specific characteristic associated with a specific service.
Definition: NimBLEClient.cpp:747
std::vector< NimBLERemoteService * >::iterator end()
Get iterator to the end of the vector of remote service pointers.
Definition: NimBLEClient.cpp:535
size_t deleteService(const NimBLEUUID &uuid)
Delete service by UUID.
Definition: NimBLEClient.cpp:131
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 paramaters to use when connecting to a server.
Definition: NimBLEClient.cpp:388
NimBLERemoteCharacteristic * getCharacteristic(const uint16_t handle)
Get the remote characteristic with the specified handle.
Definition: NimBLEClient.cpp:773
void discoverAttributes()
Retrieves the full database of attributes that the peripheral has available.
Definition: NimBLEClient.cpp:612
void setConnectTimeout(uint8_t timeout)
Set the timeout to wait for connection attempt to complete.
Definition: NimBLEClient.cpp:461
NimBLEConnInfo getConnInfo()
Get detailed information about the current peer connection.
Definition: NimBLEClient.cpp:442
int disconnect(uint8_t reason=BLE_ERR_REM_USER_CONN_TERM)
Disconnect from the peer.
Definition: NimBLEClient.cpp:336
void deleteServices()
Delete all service objects created by this client and clear the vector.
Definition: NimBLEClient.cpp:114
bool secureConnection()
Initiate a secure connection (pair/bond) with the server. Called automatically when a characteristic ...
Definition: NimBLEClient.cpp:307
void setPeerAddress(const NimBLEAddress &address)
Set the peer address.
Definition: NimBLEClient.cpp:488
uint16_t getConnId()
Get the connection id for this client.
Definition: NimBLEClient.cpp:470
bool connect(NimBLEAdvertisedDevice *device, bool deleteAttibutes=true)
Connect to an advertising device.
Definition: NimBLEClient.cpp:165
std::vector< NimBLERemoteService * >::iterator begin()
Get iterator to the beginning of the vector of remote service pointers.
Definition: NimBLEClient.cpp:526
uint16_t getMTU()
Get the current mtu of this connection.
Definition: NimBLEClient.cpp:798
std::string toString()
Return a string representation of this client.
Definition: NimBLEClient.cpp:1127
std::vector< NimBLERemoteService * > * getServices(bool refresh=false)
Get a pointer to the vector of found services.
Definition: NimBLEClient.cpp:594
int getRssi()
Ask the BLE server for the RSSI value.
Definition: NimBLEClient.cpp:503
NimBLERemoteService * getService(const char *uuid)
Get the service BLE Remote Service instance corresponding to the uuid.
Definition: NimBLEClient.cpp:545
void setClientCallbacks(NimBLEClientCallbacks *pClientCallbacks, bool deleteCallbacks=true)
Set the callbacks that will be invoked when events are received.
Definition: NimBLEClient.cpp:1113
bool isConnected()
Are we connected to a server?
Definition: NimBLEClient.cpp:1103
std::string getValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID)
Get the value of a specific characteristic associated with a specific service.
Definition: NimBLEClient.cpp:720
void updateConnParams(uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout)
Update the connection parameters:
Definition: NimBLEClient.cpp:418
Connection information.
Definition: NimBLEConnInfo.h:9
A model of a BLE Device from which all the BLE roles are created.
Definition: NimBLEDevice.h:91
A model of a remote BLE characteristic.
Definition: NimBLERemoteCharacteristic.h:45
A model of a remote BLE service.
Definition: NimBLERemoteService.h:36
A model of a BLE UUID.
Definition: NimBLEUUID.h:31