15#ifndef COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_
16#define COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_
19#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
21#include "NimBLERemoteService.h"
22#include "NimBLERemoteDescriptor.h"
33 uint8_t* pData,
size_t length,
bool isNotify)> notify_callback;
55 std::vector<NimBLERemoteDescriptor*>::iterator
begin();
56 std::vector<NimBLERemoteDescriptor*>::iterator
end();
58 std::vector<NimBLERemoteDescriptor*>*
getDescriptors(
bool refresh =
false);
68 uint8_t
readUInt8() __attribute__ ((deprecated(
"Use template readValue<uint8_t>()")));
69 uint16_t
readUInt16() __attribute__ ((deprecated(
"Use template readValue<uint16_t>()")));
70 uint32_t
readUInt32() __attribute__ ((deprecated(
"Use template readValue<uint32_t>()")));
71 float readFloat() __attribute__ ((deprecated(
"Use template readValue<float>()")));
75 notify_callback notifyCallback =
nullptr,
76 bool response =
false);
79 bool notifications =
true,
81 __attribute__ ((deprecated(
"Use subscribe()/unsubscribe()")));
84 bool response =
false);
85 bool writeValue(
const std::vector<uint8_t>& v,
bool response =
false);
86 bool writeValue(
const char* s,
bool response =
false);
101 typename std::enable_if<!std::is_array<T>::value && !Has_c_str_len<T>::value,
bool>::type
104 return writeValue((uint8_t*)&s,
sizeof(T), response);
117 typename std::enable_if<Has_c_str_len<T>::value,
bool>::type
120 return writeValue((uint8_t*)s.c_str(), s.length(), response);
133 T
getValue(time_t *timestamp =
nullptr,
bool skipSizeCheck =
false) {
134 if(!skipSizeCheck && m_value.
size() <
sizeof(T))
return T();
135 return *((T *)m_value.
getValue(timestamp));
148 T
readValue(time_t *timestamp =
nullptr,
bool skipSizeCheck =
false) {
150 if(!skipSizeCheck && value.
size() <
sizeof(T))
return T();
151 return *((T *)value.
getValue(timestamp));
163 bool setNotify(uint16_t val, notify_callback notifyCallback =
nullptr,
bool response =
true);
164 bool retrieveDescriptors(
const NimBLEUUID *uuid_filter =
nullptr);
165 static int onReadCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
166 struct ble_gatt_attr *attr,
void *arg);
167 static int onWriteCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
168 struct ble_gatt_attr *attr,
void *arg);
169 static int descriptorDiscCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
170 uint16_t chr_val_handle,
const struct ble_gatt_dsc *dsc,
172 static int nextCharCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
173 const struct ble_gatt_chr *chr,
void *arg);
179 uint16_t m_defHandle;
180 uint16_t m_endHandle;
183 notify_callback m_notifyCallback;
186 std::vector<NimBLERemoteDescriptor*> m_descriptorVector;
A specialized container class to hold BLE attribute values.
Definition: NimBLEAttValue.h:61
const uint8_t * getValue(time_t *timestamp)
Get a pointer to the value buffer with timestamp.
Definition: NimBLEAttValue.h:369
uint16_t size() const
Returns the current size of the value in bytes.
Definition: NimBLEAttValue.h:151
A model of a BLE client.
Definition: NimBLEClient.h:39
A model of a remote BLE characteristic.
Definition: NimBLERemoteCharacteristic.h:44
bool canRead()
Does the characteristic support reading?
Definition: NimBLERemoteCharacteristic.cpp:115
uint16_t readUInt16() __attribute__((deprecated("Use template readValue<uint16_t>()")))
Read an unsigned 16 bit value.
Definition: NimBLERemoteCharacteristic.cpp:451
bool canWriteNoResponse()
Does the characteristic support writing with no response?
Definition: NimBLERemoteCharacteristic.cpp:133
std::vector< NimBLERemoteDescriptor * >::iterator end()
Get iterator to the end of the vector of remote descriptor pointers.
Definition: NimBLERemoteCharacteristic.cpp:392
bool writeValue(const uint8_t *data, size_t length, bool response=false)
Write a new value to the remote characteristic from a data buffer.
Definition: NimBLERemoteCharacteristic.cpp:764
NimBLEAttValue readValue(time_t *timestamp=nullptr)
Read the value of the remote characteristic.
Definition: NimBLERemoteCharacteristic.cpp:490
T readValue(time_t *timestamp=nullptr, bool skipSizeCheck=false)
Template to convert the remote characteristic data to <type>.
Definition: NimBLERemoteCharacteristic.h:148
std::string toString()
Convert a NimBLERemoteCharacteristic to a string representation;.
Definition: NimBLERemoteCharacteristic.cpp:713
bool canIndicate()
Does the characteristic support indications?
Definition: NimBLERemoteCharacteristic.cpp:97
void deleteDescriptors()
Delete the descriptors in the descriptor vector.
Definition: NimBLERemoteCharacteristic.cpp:676
NimBLERemoteDescriptor * getDescriptor(const NimBLEUUID &uuid)
Get the descriptor instance with the given UUID that belongs to this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:307
NimBLEAttValue getValue(time_t *timestamp=nullptr)
Get the value of the remote characteristic.
Definition: NimBLERemoteCharacteristic.cpp:437
bool unsubscribe(bool response=false)
Unsubscribe for notifications or indications.
Definition: NimBLERemoteCharacteristic.cpp:645
bool canBroadcast()
Does the characteristic support broadcasting?
Definition: NimBLERemoteCharacteristic.cpp:88
uint32_t readUInt32() __attribute__((deprecated("Use template readValue<uint32_t>()")))
Read an unsigned 32 bit value.
Definition: NimBLERemoteCharacteristic.cpp:461
T getValue(time_t *timestamp=nullptr, bool skipSizeCheck=false)
Template to convert the remote characteristic data to <type>.
Definition: NimBLERemoteCharacteristic.h:133
std::vector< NimBLERemoteDescriptor * >::iterator begin()
Get iterator to the beginning of the vector of remote descriptor pointers.
Definition: NimBLERemoteCharacteristic.cpp:383
float readFloat() __attribute__((deprecated("Use template readValue<float>()")))
Read a float value.
Definition: NimBLERemoteCharacteristic.cpp:480
~NimBLERemoteCharacteristic()
Destructor.
Definition: NimBLERemoteCharacteristic.cpp:69
NimBLERemoteService * getRemoteService()
Get the remote service associated with this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:418
bool canNotify()
Does the characteristic support notifications?
Definition: NimBLERemoteCharacteristic.cpp:106
bool subscribe(bool notifications=true, notify_callback notifyCallback=nullptr, bool response=false)
Subscribe for notifications or indications.
Definition: NimBLERemoteCharacteristic.cpp:631
size_t deleteDescriptor(const NimBLEUUID &uuid)
Delete descriptor by UUID.
Definition: NimBLERemoteCharacteristic.cpp:692
bool canWrite()
Does the characteristic support writing?
Definition: NimBLERemoteCharacteristic.cpp:124
uint16_t getHandle()
Get the handle for this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:401
bool registerForNotify(notify_callback notifyCallback, bool notifications=true, bool response=true) __attribute__((deprecated("Use subscribe()/unsubscribe()")))
backward-compatibility method for subscribe/unsubscribe notifications/indications
Definition: NimBLERemoteCharacteristic.cpp:659
std::vector< NimBLERemoteDescriptor * > * getDescriptors(bool refresh=false)
Get a pointer to the vector of found descriptors.
Definition: NimBLERemoteCharacteristic.cpp:364
bool writeValue(const T &s, bool response=false)
Template to set the remote characteristic value to <type>val.
Definition: NimBLERemoteCharacteristic.h:103
NimBLEUUID getUUID()
Get the UUID for this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:427
uint8_t readUInt8() __attribute__((deprecated("Use template readValue<uint8_t>()")))
Read a byte value.
Definition: NimBLERemoteCharacteristic.cpp:471
uint16_t getDefHandle()
Get the handle for this characteristics definition.
Definition: NimBLERemoteCharacteristic.cpp:409
A model of remote BLE descriptor.
Definition: NimBLERemoteDescriptor.h:27
A model of a remote BLE service.
Definition: NimBLERemoteService.h:34
A model of a BLE UUID.
Definition: NimBLEUUID.h:37