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"
32 uint8_t* pData,
size_t length,
bool isNotify)> notify_callback;
54 std::vector<NimBLERemoteDescriptor*>::iterator
begin();
55 std::vector<NimBLERemoteDescriptor*>::iterator
end();
57 std::vector<NimBLERemoteDescriptor*>*
getDescriptors(
bool refresh =
false);
63 std::string
readValue(time_t *timestamp =
nullptr);
75 T
readValue(time_t *timestamp =
nullptr,
bool skipSizeCheck =
false) {
77 if(!skipSizeCheck && value.size() <
sizeof(T))
return T();
78 const char *pData = value.data();
86 std::
string getValue(time_t *timestamp =
nullptr);
98 T
getValue(time_t *timestamp =
nullptr,
bool skipSizeCheck = false) {
99 std::string value =
getValue(timestamp);
100 if(!skipSizeCheck && value.size() <
sizeof(T))
return T();
101 const char *pData = value.data();
102 return *((T *)pData);
105 bool subscribe(
bool notifications =
true,
106 notify_callback notifyCallback =
nullptr,
107 bool response =
false);
110 bool notifications =
true,
111 bool response =
true)
115 bool response = false);
117 bool response = false);
125 return writeValue((uint8_t*)&s,
sizeof(T), response);
140 bool setNotify(uint16_t val, notify_callback notifyCallback =
nullptr,
bool response =
true);
141 bool retrieveDescriptors(
const NimBLEUUID *uuid_filter =
nullptr);
142 static int onReadCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
143 struct ble_gatt_attr *attr,
void *arg);
144 static int onWriteCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
145 struct ble_gatt_attr *attr,
void *arg);
146 static int descriptorDiscCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
147 uint16_t chr_val_handle,
const struct ble_gatt_dsc *dsc,
149 static int nextCharCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
150 const struct ble_gatt_chr *chr,
void *arg);
156 uint16_t m_defHandle;
157 uint16_t m_endHandle;
160 notify_callback m_notifyCallback;
164 std::vector<NimBLERemoteDescriptor*> m_descriptorVector;
A model of a BLE client.
Definition: NimBLEClient.h:38
A model of a remote BLE characteristic.
Definition: NimBLERemoteCharacteristic.h:43
bool canRead()
Does the characteristic support reading?
Definition: NimBLERemoteCharacteristic.cpp:116
uint16_t readUInt16() __attribute__((deprecated("Use template readValue<uint16_t>()")))
Read an unsigned 16 bit value.
Definition: NimBLERemoteCharacteristic.cpp:434
bool canWriteNoResponse()
Does the characteristic support writing with no response?
Definition: NimBLERemoteCharacteristic.cpp:134
std::vector< NimBLERemoteDescriptor * >::iterator end()
Get iterator to the end of the vector of remote descriptor pointers.
Definition: NimBLERemoteCharacteristic.cpp:372
bool writeValue(const uint8_t *data, size_t length, bool response=false)
Write the new value for the characteristic from a data buffer.
Definition: NimBLERemoteCharacteristic.cpp:739
T readValue(time_t *timestamp=nullptr, bool skipSizeCheck=false)
A template to convert the remote characteristic data to <type>.
Definition: NimBLERemoteCharacteristic.h:75
std::string toString()
Convert a NimBLERemoteCharacteristic to a string representation;.
Definition: NimBLERemoteCharacteristic.cpp:699
bool canIndicate()
Does the characteristic support indications?
Definition: NimBLERemoteCharacteristic.cpp:98
void deleteDescriptors()
Delete the descriptors in the descriptor vector.
Definition: NimBLERemoteCharacteristic.cpp:662
NimBLERemoteDescriptor * getDescriptor(const NimBLEUUID &uuid)
Get the descriptor instance with the given UUID that belongs to this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:304
bool unsubscribe(bool response=false)
Unsubscribe for notifications or indications.
Definition: NimBLERemoteCharacteristic.cpp:631
bool canBroadcast()
Does the characteristic support broadcasting?
Definition: NimBLERemoteCharacteristic.cpp:89
uint32_t readUInt32() __attribute__((deprecated("Use template readValue<uint32_t>()")))
Read an unsigned 32 bit value.
Definition: NimBLERemoteCharacteristic.cpp:444
std::vector< NimBLERemoteDescriptor * >::iterator begin()
Get iterator to the beginning of the vector of remote descriptor pointers.
Definition: NimBLERemoteCharacteristic.cpp:363
std::string readValue(time_t *timestamp=nullptr)
Read the value of the remote characteristic.
Definition: NimBLERemoteCharacteristic.cpp:473
float readFloat() __attribute__((deprecated("Use template readValue<float>()")))
Read a float value.
Definition: NimBLERemoteCharacteristic.cpp:463
~NimBLERemoteCharacteristic()
Destructor.
Definition: NimBLERemoteCharacteristic.cpp:70
NimBLERemoteService * getRemoteService()
Get the remote service associated with this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:398
bool canNotify()
Does the characteristic support notifications?
Definition: NimBLERemoteCharacteristic.cpp:107
bool subscribe(bool notifications=true, notify_callback notifyCallback=nullptr, bool response=false)
Subscribe for notifications or indications.
Definition: NimBLERemoteCharacteristic.cpp:617
size_t deleteDescriptor(const NimBLEUUID &uuid)
Delete descriptor by UUID.
Definition: NimBLERemoteCharacteristic.cpp:678
bool canWrite()
Does the characteristic support writing?
Definition: NimBLERemoteCharacteristic.cpp:125
uint16_t getHandle()
Get the handle for this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:381
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:645
std::vector< NimBLERemoteDescriptor * > * getDescriptors(bool refresh=false)
Get a pointer to the vector of found descriptors.
Definition: NimBLERemoteCharacteristic.cpp:344
NimBLEUUID getUUID()
Get the UUID for this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:407
std::string getValue(time_t *timestamp=nullptr)
Get the value of the remote characteristic.
Definition: NimBLERemoteCharacteristic.cpp:417
uint8_t readUInt8() __attribute__((deprecated("Use template readValue<uint8_t>()")))
Read a byte value.
Definition: NimBLERemoteCharacteristic.cpp:454
uint16_t getDefHandle()
Get the handle for this characteristics definition.
Definition: NimBLERemoteCharacteristic.cpp:389
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