esp-nimble-cpp
1.4.0
|
The model of a BLE server. More...
Public Member Functions | |
size_t | getConnectedCount () |
Return the number of connected clients. More... | |
NimBLEService * | createService (const char *uuid) |
Create a BLE Service. More... | |
NimBLEService * | createService (const NimBLEUUID &uuid) |
Create a BLE Service. More... | |
void | removeService (NimBLEService *service, bool deleteSvc=false) |
Remove a service from the server. More... | |
void | addService (NimBLEService *service) |
Adds a service which was either already created but removed from availability, or created and later added to services list. More... | |
void | setCallbacks (NimBLEServerCallbacks *pCallbacks, bool deleteCallbacks=true) |
Set the server callbacks. More... | |
NimBLEExtAdvertising * | getAdvertising () |
Retrieve the advertising object that can be used to advertise the existence of the server. More... | |
bool | startAdvertising (uint8_t inst_id, int duration=0, int max_events=0) |
Start advertising. More... | |
bool | stopAdvertising (uint8_t inst_id) |
Convenience function to stop advertising a data set. More... | |
bool | stopAdvertising () |
Stop advertising. More... | |
void | start () |
Start the GATT server. Required to be called after setup of all services and characteristics / descriptors for the NimBLE host to register them. | |
NimBLEService * | getServiceByUUID (const char *uuid, uint16_t instanceId=0) |
Get a BLE Service by its UUID. More... | |
NimBLEService * | getServiceByUUID (const NimBLEUUID &uuid, uint16_t instanceId=0) |
Get a BLE Service by its UUID. More... | |
NimBLEService * | getServiceByHandle (uint16_t handle) |
Get a BLE Service by its handle. More... | |
int | disconnect (uint16_t connID, uint8_t reason=BLE_ERR_REM_USER_CONN_TERM) |
Disconnect the specified client with optional reason. More... | |
void | updateConnParams (uint16_t conn_handle, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout) |
Request an Update the connection parameters: More... | |
void | setDataLen (uint16_t conn_handle, uint16_t tx_octets) |
Request an update of the data packet length. More... | |
uint16_t | getPeerMTU (uint16_t conn_id) |
Get the MTU of the client. More... | |
std::vector< uint16_t > | getPeerDevices () |
Get the vector of the connected client ID's. | |
NimBLEConnInfo | getPeerInfo (size_t index) |
Get the connection information of a connected peer by vector index. More... | |
NimBLEConnInfo | getPeerInfo (const NimBLEAddress &address) |
Get the connection information of a connected peer by address. More... | |
NimBLEConnInfo | getPeerIDInfo (uint16_t id) |
Get the connection information of a connected peer by connection ID. More... | |
void | advertiseOnDisconnect (bool) |
Set the server to automatically start advertising when a client disconnects. More... | |
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 | aod | ) |
Set the server to automatically start advertising when a client disconnects.
[in] | aod | 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. |
int NimBLEServer::disconnect | ( | uint16_t | connId, |
uint8_t | reason = BLE_ERR_REM_USER_CONN_TERM |
||
) |
Disconnect the specified client with optional reason.
[in] | connId | Connection Id of the client to disconnect. |
[in] | reason | code for disconnecting. |
NimBLEAdvertising * NimBLEServer::getAdvertising | ( | ) |
Retrieve the advertising object that can be used to advertise the existence of the server.
size_t NimBLEServer::getConnectedCount | ( | ) |
Return the number of connected clients.
NimBLEConnInfo NimBLEServer::getPeerIDInfo | ( | uint16_t | id | ) |
Get the connection information of a connected peer by connection ID.
[in] | id | The connection id of the peer. |
NimBLEConnInfo NimBLEServer::getPeerInfo | ( | const NimBLEAddress & | address | ) |
Get the connection information of a connected peer by address.
[in] | address | The address of the peer. |
NimBLEConnInfo NimBLEServer::getPeerInfo | ( | size_t | index | ) |
Get the connection information of a connected peer by vector index.
[in] | index | The vector index of the peer. |
uint16_t NimBLEServer::getPeerMTU | ( | uint16_t | conn_id | ) |
Get the MTU of the client.
NimBLEService * NimBLEServer::getServiceByHandle | ( | uint16_t | handle | ) |
Get a BLE Service by its handle.
handle | The handle of the service. |
NimBLEService * NimBLEServer::getServiceByUUID | ( | const char * | uuid, |
uint16_t | instanceId = 0 |
||
) |
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 |
||
) |
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 | conn_handle, |
uint16_t | tx_octets | ||
) |
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] | conn_handle | The connection handle of the peer to send the request to. |
[in] | tx_octets | The preferred number of payload octets to use (Range 0x001B-0x00FB). |
bool NimBLEServer::startAdvertising | ( | uint8_t | inst_id, |
int | duration = 0 , |
||
int | max_events = 0 |
||
) |
Start advertising.
[in] | inst_id | The extended advertisement instance ID to start. |
[in] | duration | How long to advertise for in milliseconds, 0 = forever (default). |
[in] | max_events | 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.
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 | ( | ) |
Stop advertising.
bool NimBLEServer::stopAdvertising | ( | uint8_t | inst_id | ) |
Convenience function to stop advertising a data set.
[in] | inst_id | The extended advertisement instance ID to stop advertising. |
void NimBLEServer::updateConnParams | ( | uint16_t | conn_handle, |
uint16_t | minInterval, | ||
uint16_t | maxInterval, | ||
uint16_t | latency, | ||
uint16_t | timeout | ||
) |
Request an Update the connection parameters:
[in] | conn_handle | 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. |