esp-nimble-cpp 2.0.1
|
The model of a BLE server. More...
#include <NimBLEServer.h>
Public Member Functions | |
void | start () |
Start the GATT server. | |
uint8_t | getConnectedCount () const |
Return the number of connected clients. | |
bool | disconnect (uint16_t connHandle, uint8_t reason=BLE_ERR_REM_USER_CONN_TERM) const |
Disconnect the specified client with optional reason. | |
bool | disconnect (const NimBLEConnInfo &connInfo, uint8_t reason=BLE_ERR_REM_USER_CONN_TERM) const |
Disconnect the specified client with optional reason. | |
void | setCallbacks (NimBLEServerCallbacks *pCallbacks, bool deleteCallbacks=true) |
Set the server callbacks. | |
void | updateConnParams (uint16_t connHandle, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout) const |
Request an Update the connection parameters: | |
NimBLEService * | createService (const char *uuid) |
Create a BLE Service. | |
NimBLEService * | createService (const NimBLEUUID &uuid) |
Create a BLE Service. | |
NimBLEService * | getServiceByUUID (const char *uuid, uint16_t instanceId=0) const |
Get a BLE Service by its UUID. | |
NimBLEService * | getServiceByUUID (const NimBLEUUID &uuid, uint16_t instanceId=0) const |
Get a BLE Service by its UUID. | |
NimBLEService * | getServiceByHandle (uint16_t handle) const |
Get a BLE Service by its handle. | |
void | removeService (NimBLEService *service, bool deleteSvc=false) |
Remove a service from the server. | |
void | addService (NimBLEService *service) |
Adds a service which was either already created but removed from availability, or created and later added to services list. | |
uint16_t | getPeerMTU (uint16_t connHandle) const |
Get the MTU value of a client connection. | |
std::vector< uint16_t > | getPeerDevices () const |
Get a vector of the connected client handles. | |
NimBLEConnInfo | getPeerInfo (uint8_t index) const |
Get the connection information of a connected peer by vector index. | |
NimBLEConnInfo | getPeerInfo (const NimBLEAddress &address) const |
Get the connection information of a connected peer by address. | |
NimBLEConnInfo | getPeerInfoByHandle (uint16_t connHandle) const |
Get the connection information of a connected peer by connection handle. | |
void | advertiseOnDisconnect (bool enable) |
Set the server to automatically start advertising when a client disconnects. | |
void | setDataLen (uint16_t connHandle, uint16_t tx_octets) const |
Request an update of the data packet length. | |
NimBLEClient * | getClient (uint16_t connHandle) |
Create a client instance from the connection handle. | |
NimBLEClient * | getClient (const NimBLEConnInfo &connInfo) |
Create a client instance from the NimBLEConnInfo reference. | |
void | deleteClient () |
Delete the NimBLEClient instance that was created with getClient() | |
NimBLEExtAdvertising * | getAdvertising () const |
Retrieve the advertising object that can be used to advertise the existence of the server. | |
bool | startAdvertising (uint8_t instanceId, int duration=0, int maxEvents=0) const |
Start advertising. | |
bool | stopAdvertising (uint8_t instanceId) const |
Convenience function to stop advertising a data set. | |
bool | updatePhy (uint16_t connHandle, uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions) |
Request an update to the PHY used for a peer connection. | |
bool | getPhy (uint16_t connHandle, uint8_t *txPhy, uint8_t *rxPhy) |
Get the PHY used for a peer connection. | |
bool | startAdvertising (uint32_t duration=0) const |
Start advertising. | |
bool | stopAdvertising () const |
Stop advertising. | |
The model of a BLE server.
void NimBLEServer::addService | ( | NimBLEService * | service | ) |
Adds a service which was either already created but removed from availability,
or created and later added to services list.
[in] | service | The service object to add. |
void NimBLEServer::advertiseOnDisconnect | ( | bool | enable | ) |
Set the server to automatically start advertising when a client disconnects.
[in] | enable | true == advertise, false == don't advertise. |
NimBLEService * NimBLEServer::createService | ( | const char * | uuid | ) |
Create a BLE Service.
[in] | uuid | The UUID of the new service. |
NimBLEService * NimBLEServer::createService | ( | const NimBLEUUID & | uuid | ) |
Create a BLE Service.
[in] | uuid | The UUID of the new service. |
bool NimBLEServer::disconnect | ( | const NimBLEConnInfo & | connInfo, |
uint8_t | reason = BLE_ERR_REM_USER_CONN_TERM |
||
) | const |
Disconnect the specified client with optional reason.
[in] | connInfo | Connection of the client to disconnect. |
[in] | reason | code for disconnecting. |
bool NimBLEServer::disconnect | ( | uint16_t | connHandle, |
uint8_t | reason = BLE_ERR_REM_USER_CONN_TERM |
||
) | const |
Disconnect the specified client with optional reason.
[in] | connHandle | Connection handle of the client to disconnect. |
[in] | reason | code for disconnecting. |
NimBLEAdvertising * NimBLEServer::getAdvertising | ( | ) | const |
Retrieve the advertising object that can be used to advertise the existence of the server.
NimBLEClient * NimBLEServer::getClient | ( | const NimBLEConnInfo & | connInfo | ) |
Create a client instance from the NimBLEConnInfo reference.
[in] | connInfo | The connection info to create a client instance from. |
NimBLEClient * NimBLEServer::getClient | ( | uint16_t | connHandle | ) |
Create a client instance from the connection handle.
[in] | connHandle | The connection handle to create a client instance from. |
uint8_t NimBLEServer::getConnectedCount | ( | ) | const |
Return the number of connected clients.
std::vector< uint16_t > NimBLEServer::getPeerDevices | ( | ) | const |
Get a vector of the connected client handles.
NimBLEConnInfo NimBLEServer::getPeerInfo | ( | const NimBLEAddress & | address | ) | const |
Get the connection information of a connected peer by address.
[in] | address | The address of the peer. |
NimBLEConnInfo NimBLEServer::getPeerInfo | ( | uint8_t | index | ) | const |
Get the connection information of a connected peer by vector index.
[in] | index | The vector index of the peer. |
NimBLEConnInfo NimBLEServer::getPeerInfoByHandle | ( | uint16_t | connHandle | ) | const |
Get the connection information of a connected peer by connection handle.
[in] | connHandle | The connection handle of the peer. |
uint16_t NimBLEServer::getPeerMTU | ( | uint16_t | connHandle | ) | const |
Get the MTU value of a client connection.
[in] | connHandle | The connection handle of the client to get the MTU value for. |
bool NimBLEServer::getPhy | ( | uint16_t | connHandle, |
uint8_t * | txPhy, | ||
uint8_t * | rxPhy | ||
) |
Get the PHY used for a peer connection.
[in] | connHandle | the connection handle to the get the PHY for. |
[out] | txPhy | The TX PHY. |
[out] | rxPhy | The RX PHY. |
NimBLEService * NimBLEServer::getServiceByHandle | ( | uint16_t | handle | ) | const |
Get a BLE Service by its handle.
handle | The handle of the service. |
NimBLEService * NimBLEServer::getServiceByUUID | ( | const char * | uuid, |
uint16_t | instanceId = 0 |
||
) | const |
Get a BLE Service by its UUID.
[in] | uuid | The UUID of the service. |
instanceId | The index of the service to return (used when multiple services have the same UUID). |
NimBLEService * NimBLEServer::getServiceByUUID | ( | const NimBLEUUID & | uuid, |
uint16_t | instanceId = 0 |
||
) | const |
Get a BLE Service by its UUID.
[in] | uuid | The UUID of the service. |
instanceId | The index of the service to return (used when multiple services have the same UUID). |
void NimBLEServer::removeService | ( | NimBLEService * | service, |
bool | deleteSvc = false |
||
) |
Remove a service from the server.
Immediately removes access to the service by clients, sends a service changed indication, and removes the service (if applicable) from the advertisements. The service is not deleted unless the deleteSvc parameter is true, otherwise the service remains available and can be re-added in the future. If desired a removed but not deleted service can be deleted later by calling this method with deleteSvc set to true.
[in] | service | The service object to remove. |
[in] | deleteSvc | true if the service should be deleted. |
void NimBLEServer::setCallbacks | ( | NimBLEServerCallbacks * | pCallbacks, |
bool | deleteCallbacks = true |
||
) |
Set the server callbacks.
As a BLE server operates, it will generate server level events such as a new client connecting or a previous client disconnecting. This function can be called to register a callback handler that will be invoked when these events are detected.
[in] | pCallbacks | The callbacks to be invoked. |
[in] | deleteCallbacks | if true callback class will be deleted when server is destructed. |
void NimBLEServer::setDataLen | ( | uint16_t | connHandle, |
uint16_t | octets | ||
) | const |
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 peer. The Data Length Extension (DLE) allows to increase the Data Channel Payload from 27 bytes to up to 251 bytes. The peer needs to support the Bluetooth 4.2 specifications, to be capable of DLE.
[in] | connHandle | The connection handle of the peer to send the request to. |
[in] | octets | The preferred number of payload octets to use (Range 0x001B-0x00FB). |
void NimBLEServer::start | ( | ) |
Start the GATT server.
Required to be called after setup of all services and characteristics / descriptors for the NimBLE host to register them.
bool NimBLEServer::startAdvertising | ( | uint32_t | duration = 0 | ) | const |
Start advertising.
[in] | duration | The duration in milliseconds to advertise for, default = forever. |
Start the server advertising its existence. This is a convenience function and is equivalent to retrieving the advertising object and invoking start upon it.
bool NimBLEServer::startAdvertising | ( | uint8_t | instId, |
int | duration = 0 , |
||
int | maxEvents = 0 |
||
) | const |
Start advertising.
[in] | instId | The extended advertisement instance ID to start. |
[in] | duration | How long to advertise for in milliseconds, 0 = forever (default). |
[in] | maxEvents | Maximum number of advertisement events to send, 0 = no limit (default). |
Start the server advertising its existence. This is a convenience function and is equivalent to retrieving the advertising object and invoking start upon it.
bool NimBLEServer::stopAdvertising | ( | ) | const |
Stop advertising.
bool NimBLEServer::stopAdvertising | ( | uint8_t | instId | ) | const |
Convenience function to stop advertising a data set.
[in] | instId | The extended advertisement instance ID to stop advertising. |
void NimBLEServer::updateConnParams | ( | uint16_t | connHandle, |
uint16_t | minInterval, | ||
uint16_t | maxInterval, | ||
uint16_t | latency, | ||
uint16_t | timeout | ||
) | const |
Request an Update the connection parameters:
[in] | connHandle | The connection handle of the peer to send the request to. |
[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 NimBLEServer::updatePhy | ( | uint16_t | connHandle, |
uint8_t | txPhyMask, | ||
uint8_t | rxPhyMask, | ||
uint16_t | phyOptions | ||
) |
Request an update to the PHY used for a peer connection.
[in] | connHandle | the connection handle to the update the PHY for. |
[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:
|