esp-nimble-cpp
1.4.0
|
The model of a BLE Characteristic. More...
Public Member Functions | |
NimBLECharacteristic (const char *uuid, uint16_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t max_len=BLE_ATT_ATTR_MAX_LEN, NimBLEService *pService=nullptr) | |
Construct a characteristic. More... | |
NimBLECharacteristic (const NimBLEUUID &uuid, uint16_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t max_len=BLE_ATT_ATTR_MAX_LEN, NimBLEService *pService=nullptr) | |
Construct a characteristic. More... | |
~NimBLECharacteristic () | |
Destructor. | |
uint16_t | getHandle () |
Get the handle of the characteristic. More... | |
NimBLEUUID | getUUID () |
Get the UUID of the characteristic. More... | |
std::string | toString () |
Return a string representation of the characteristic. More... | |
void | indicate () |
Send an indication. | |
void | indicate (const uint8_t *value, size_t length) |
Send an indication. More... | |
void | indicate (const std::vector< uint8_t > &value) |
Send an indication. More... | |
void | notify (bool is_notification=true) |
Send a notification or indication. More... | |
void | notify (const uint8_t *value, size_t length, bool is_notification=true) |
Send a notification or indication. More... | |
void | notify (const std::vector< uint8_t > &value, bool is_notification=true) |
Send a notification or indication. More... | |
size_t | getSubscribedCount () |
Get the number of clients subscribed to the characteristic. More... | |
void | addDescriptor (NimBLEDescriptor *pDescriptor) |
Add a descriptor to the characteristic. More... | |
NimBLEDescriptor * | getDescriptorByUUID (const char *uuid) |
Return the BLE Descriptor for the given UUID. More... | |
NimBLEDescriptor * | getDescriptorByUUID (const NimBLEUUID &uuid) |
Return the BLE Descriptor for the given UUID. More... | |
NimBLEDescriptor * | getDescriptorByHandle (uint16_t handle) |
Return the BLE Descriptor for the given handle. More... | |
void | removeDescriptor (NimBLEDescriptor *pDescriptor, bool deleteDsc=false) |
Remove a descriptor from the characteristic. More... | |
NimBLEService * | getService () |
Get the service associated with this characteristic. | |
uint16_t | getProperties () |
Get the properties of the characteristic. More... | |
NimBLEAttValue | getValue (time_t *timestamp=nullptr) |
Retrieve the current value of the characteristic. More... | |
size_t | getDataLength () |
Retrieve the the current data length of the characteristic. More... | |
void | setValue (const uint8_t *data, size_t size) |
Set the value of the characteristic from a data buffer . More... | |
void | setValue (const std::vector< uint8_t > &vec) |
Set the value of the characteristic from a std::vector<uint8_t> .. More... | |
void | setCallbacks (NimBLECharacteristicCallbacks *pCallbacks) |
Set the callback handlers for this characteristic. More... | |
NimBLEDescriptor * | createDescriptor (const char *uuid, uint32_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t max_len=BLE_ATT_ATTR_MAX_LEN) |
Create a new BLE Descriptor associated with this characteristic. More... | |
NimBLEDescriptor * | createDescriptor (const NimBLEUUID &uuid, uint32_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t max_len=BLE_ATT_ATTR_MAX_LEN) |
Create a new BLE Descriptor associated with this characteristic. More... | |
NimBLECharacteristicCallbacks * | getCallbacks () |
Get the callback handlers for this characteristic. | |
template<typename T > | |
void | setValue (const T &s) |
Template to set the characteristic value to <type>val. More... | |
template<typename T > | |
T | getValue (time_t *timestamp=nullptr, bool skipSizeCheck=false) |
Template to convert the characteristic data to <type>. More... | |
template<typename T > | |
void | notify (const T &value, bool is_notification=true) |
Template to send a notification from a class type that has a c_str() and length() method. More... | |
template<typename T > | |
void | indicate (const T &value) |
Template to send an indication from a class type that has a c_str() and length() method. More... | |
The model of a BLE Characteristic.
A BLE Characteristic is an identified value container that manages a value. It is exposed by a BLE server and can be read and written to by a BLE client.
NimBLECharacteristic::NimBLECharacteristic | ( | const char * | uuid, |
uint16_t | properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE , |
||
uint16_t | max_len = BLE_ATT_ATTR_MAX_LEN , |
||
NimBLEService * | pService = nullptr |
||
) |
Construct a characteristic.
[in] | uuid | - UUID (const char*) for the characteristic. |
[in] | properties | - Properties for the characteristic. |
[in] | max_len | - The maximum length in bytes that the characteristic value can hold. (Default: 512 bytes for esp32, 20 for all others). |
[in] | pService | - pointer to the service instance this characteristic belongs to. |
NimBLECharacteristic::NimBLECharacteristic | ( | const NimBLEUUID & | uuid, |
uint16_t | properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE , |
||
uint16_t | max_len = BLE_ATT_ATTR_MAX_LEN , |
||
NimBLEService * | pService = nullptr |
||
) |
Construct a characteristic.
[in] | uuid | - UUID for the characteristic. |
[in] | properties | - Properties for the characteristic. |
[in] | max_len | - The maximum length in bytes that the characteristic value can hold. (Default: 512 bytes for esp32, 20 for all others). |
[in] | pService | - pointer to the service instance this characteristic belongs to. |
void NimBLECharacteristic::addDescriptor | ( | NimBLEDescriptor * | pDescriptor | ) |
Add a descriptor to the characteristic.
[in] | pDescriptor | A pointer to the descriptor to add. |
NimBLEDescriptor * NimBLECharacteristic::createDescriptor | ( | const char * | uuid, |
uint32_t | properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE , |
||
uint16_t | max_len = BLE_ATT_ATTR_MAX_LEN |
||
) |
Create a new BLE Descriptor associated with this characteristic.
[in] | uuid | - The UUID of the descriptor. |
[in] | properties | - The properties of the descriptor. |
[in] | max_len | - The max length in bytes of the descriptor value. |
NimBLEDescriptor * NimBLECharacteristic::createDescriptor | ( | const NimBLEUUID & | uuid, |
uint32_t | properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE , |
||
uint16_t | max_len = BLE_ATT_ATTR_MAX_LEN |
||
) |
Create a new BLE Descriptor associated with this characteristic.
[in] | uuid | - The UUID of the descriptor. |
[in] | properties | - The properties of the descriptor. |
[in] | max_len | - The max length in bytes of the descriptor value. |
size_t NimBLECharacteristic::getDataLength | ( | ) |
Retrieve the the current data length of the characteristic.
NimBLEDescriptor * NimBLECharacteristic::getDescriptorByHandle | ( | uint16_t | handle | ) |
Return the BLE Descriptor for the given handle.
[in] | handle | The handle of the descriptor. |
NimBLEDescriptor * NimBLECharacteristic::getDescriptorByUUID | ( | const char * | uuid | ) |
Return the BLE Descriptor for the given UUID.
[in] | uuid | The UUID of the descriptor. |
NimBLEDescriptor * NimBLECharacteristic::getDescriptorByUUID | ( | const NimBLEUUID & | uuid | ) |
Return the BLE Descriptor for the given UUID.
[in] | uuid | The UUID of the descriptor. |
uint16_t NimBLECharacteristic::getHandle | ( | ) |
Get the handle of the characteristic.
uint16_t NimBLECharacteristic::getProperties | ( | ) |
Get the properties of the characteristic.
size_t NimBLECharacteristic::getSubscribedCount | ( | ) |
Get the number of clients subscribed to the characteristic.
NimBLEUUID NimBLECharacteristic::getUUID | ( | ) |
Get the UUID of the characteristic.
NimBLEAttValue NimBLECharacteristic::getValue | ( | time_t * | timestamp = nullptr | ) |
Retrieve the current value of the characteristic.
|
inline |
Template to convert the characteristic data to <type>.
T | The type to convert the data to. |
[in] | timestamp | (Optional) A pointer to a time_t struct to store the time the value was read. |
[in] | skipSizeCheck | (Optional) If true it will skip checking if the data size is less than sizeof(<type>) . |
sizeof(<type>)
.Use: getValue<type>(×tamp, skipSizeCheck);
void NimBLECharacteristic::indicate | ( | const std::vector< uint8_t > & | value | ) |
Send an indication.
[in] | value | A std::vector<uint8_t> containing the value to send as the notification value. |
|
inline |
Template to send an indication from a class type that has a c_str() and length() method.
T | The a reference to a class containing the data to send. |
[in] | value | The <type>value to set. |
Only used if the <type> has a c_str()
method.
void NimBLECharacteristic::indicate | ( | const uint8_t * | value, |
size_t | length | ||
) |
Send an indication.
[in] | value | A pointer to the data to send. |
[in] | length | The length of the data to send. |
void NimBLECharacteristic::notify | ( | bool | is_notification = true | ) |
Send a notification or indication.
[in] | is_notification | if true sends a notification, false sends an indication. |
void NimBLECharacteristic::notify | ( | const std::vector< uint8_t > & | value, |
bool | is_notification = true |
||
) |
Send a notification or indication.
[in] | value | A std::vector<uint8_t> containing the value to send as the notification value. |
[in] | is_notification | if true sends a notification, false sends an indication. |
|
inline |
Template to send a notification from a class type that has a c_str() and length() method.
T | The a reference to a class containing the data to send. |
[in] | value | The <type>value to set. |
[in] | is_notification | if true sends a notification, false sends an indication. |
Only used if the <type> has a c_str()
method.
void NimBLECharacteristic::notify | ( | const uint8_t * | value, |
size_t | length, | ||
bool | is_notification = true |
||
) |
Send a notification or indication.
[in] | value | A pointer to the data to send. |
[in] | length | The length of the data to send. |
[in] | is_notification | if true sends a notification, false sends an indication. |
void NimBLECharacteristic::removeDescriptor | ( | NimBLEDescriptor * | pDescriptor, |
bool | deleteDsc = false |
||
) |
Remove a descriptor from the characteristic.
[in] | pDescriptor | A pointer to the descriptor instance to remove from the characteristic. |
[in] | deleteDsc | If true it will delete the descriptor instance and free it's resources. |
void NimBLECharacteristic::setCallbacks | ( | NimBLECharacteristicCallbacks * | pCallbacks | ) |
Set the callback handlers for this characteristic.
[in] | pCallbacks | An instance of a NimBLECharacteristicCallbacks class used to define any callbacks for the characteristic. |
void NimBLECharacteristic::setValue | ( | const std::vector< uint8_t > & | vec | ) |
Set the value of the characteristic from a std::vector<uint8_t>
.
.
[in] | vec | The std::vector<uint8_t> reference to set the characteristic value from. |
|
inline |
Template to set the characteristic value to <type>val.
[in] | s | The value to set. |
void NimBLECharacteristic::setValue | ( | const uint8_t * | data, |
size_t | length | ||
) |
Set the value of the characteristic from a data buffer .
[in] | data | The data buffer to set for the characteristic. |
[in] | length | The number of bytes in the data buffer. |
std::string NimBLECharacteristic::toString | ( | ) |
Return a string representation of the characteristic.