15 #ifndef COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_
16 #define COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_
17 #include "sdkconfig.h"
18 #if defined(CONFIG_BT_ENABLED)
21 #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
23 #include "NimBLERemoteService.h"
24 #include "NimBLERemoteDescriptor.h"
34 uint8_t* pData,
size_t length,
bool isNotify)> notify_callback;
56 std::vector<NimBLERemoteDescriptor*>::iterator
begin();
57 std::vector<NimBLERemoteDescriptor*>::iterator
end();
59 std::vector<NimBLERemoteDescriptor*>*
getDescriptors(
bool refresh =
false);
65 std::string
readValue(time_t *timestamp =
nullptr);
77 T
readValue(time_t *timestamp =
nullptr,
bool skipSizeCheck =
false) {
79 if(!skipSizeCheck && value.size() <
sizeof(T))
return T();
80 const char *pData = value.data();
88 std::
string getValue(time_t *timestamp =
nullptr);
100 T
getValue(time_t *timestamp =
nullptr,
bool skipSizeCheck = false) {
101 std::string value =
getValue(timestamp);
102 if(!skipSizeCheck && value.size() <
sizeof(T))
return T();
103 const char *pData = value.data();
104 return *((T *)pData);
107 bool subscribe(
bool notifications =
true,
108 notify_callback notifyCallback =
nullptr,
109 bool response =
false);
112 bool notifications =
true,
113 bool response =
true)
117 bool response = false);
119 bool response = false);
127 return writeValue((uint8_t*)&s,
sizeof(T), response);
142 bool setNotify(uint16_t val, notify_callback notifyCallback =
nullptr,
bool response =
true);
143 bool retrieveDescriptors(
const NimBLEUUID *uuid_filter =
nullptr);
144 static int onReadCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
145 struct ble_gatt_attr *attr,
void *arg);
146 static int onWriteCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
147 struct ble_gatt_attr *attr,
void *arg);
148 static int descriptorDiscCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
149 uint16_t chr_val_handle,
const struct ble_gatt_dsc *dsc,
151 static int nextCharCB(uint16_t conn_handle,
const struct ble_gatt_error *error,
152 const struct ble_gatt_chr *chr,
void *arg);
158 uint16_t m_defHandle;
159 uint16_t m_endHandle;
162 notify_callback m_notifyCallback;
164 portMUX_TYPE m_valMux;
167 std::vector<NimBLERemoteDescriptor*> m_descriptorVector;
A model of a BLE client.
Definition: NimBLEClient.h:41
A model of a remote BLE characteristic.
Definition: NimBLERemoteCharacteristic.h:45
bool canRead()
Does the characteristic support reading?
Definition: NimBLERemoteCharacteristic.cpp:118
uint16_t readUInt16() __attribute__((deprecated("Use template readValue<uint16_t>()")))
Read an unsigned 16 bit value.
Definition: NimBLERemoteCharacteristic.cpp:427
bool canWriteNoResponse()
Does the characteristic support writing with no response?
Definition: NimBLERemoteCharacteristic.cpp:136
std::vector< NimBLERemoteDescriptor * >::iterator end()
Get iterator to the end of the vector of remote descriptor pointers.
Definition: NimBLERemoteCharacteristic.cpp:365
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:726
T readValue(time_t *timestamp=nullptr, bool skipSizeCheck=false)
A template to convert the remote characteristic data to <type>.
Definition: NimBLERemoteCharacteristic.h:77
std::string toString()
Convert a NimBLERemoteCharacteristic to a string representation;.
Definition: NimBLERemoteCharacteristic.cpp:686
bool canIndicate()
Does the characteristic support indications?
Definition: NimBLERemoteCharacteristic.cpp:100
void deleteDescriptors()
Delete the descriptors in the descriptor vector.
Definition: NimBLERemoteCharacteristic.cpp:649
NimBLERemoteDescriptor * getDescriptor(const NimBLEUUID &uuid)
Get the descriptor instance with the given UUID that belongs to this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:297
bool unsubscribe(bool response=false)
Unsubscribe for notifications or indications.
Definition: NimBLERemoteCharacteristic.cpp:618
bool canBroadcast()
Does the characteristic support broadcasting?
Definition: NimBLERemoteCharacteristic.cpp:91
uint32_t readUInt32() __attribute__((deprecated("Use template readValue<uint32_t>()")))
Read an unsigned 32 bit value.
Definition: NimBLERemoteCharacteristic.cpp:437
std::vector< NimBLERemoteDescriptor * >::iterator begin()
Get iterator to the beginning of the vector of remote descriptor pointers.
Definition: NimBLERemoteCharacteristic.cpp:356
std::string readValue(time_t *timestamp=nullptr)
Read the value of the remote characteristic.
Definition: NimBLERemoteCharacteristic.cpp:466
float readFloat() __attribute__((deprecated("Use template readValue<float>()")))
Read a float value.
Definition: NimBLERemoteCharacteristic.cpp:456
~NimBLERemoteCharacteristic()
Destructor.
Definition: NimBLERemoteCharacteristic.cpp:72
NimBLERemoteService * getRemoteService()
Get the remote service associated with this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:391
bool canNotify()
Does the characteristic support notifications?
Definition: NimBLERemoteCharacteristic.cpp:109
bool subscribe(bool notifications=true, notify_callback notifyCallback=nullptr, bool response=false)
Subscribe for notifications or indications.
Definition: NimBLERemoteCharacteristic.cpp:604
size_t deleteDescriptor(const NimBLEUUID &uuid)
Delete descriptor by UUID.
Definition: NimBLERemoteCharacteristic.cpp:665
bool canWrite()
Does the characteristic support writing?
Definition: NimBLERemoteCharacteristic.cpp:127
uint16_t getHandle()
Get the handle for this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:374
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:632
std::vector< NimBLERemoteDescriptor * > * getDescriptors(bool refresh=false)
Get a pointer to the vector of found descriptors.
Definition: NimBLERemoteCharacteristic.cpp:337
NimBLEUUID getUUID()
Get the UUID for this characteristic.
Definition: NimBLERemoteCharacteristic.cpp:400
std::string getValue(time_t *timestamp=nullptr)
Get the value of the remote characteristic.
Definition: NimBLERemoteCharacteristic.cpp:410
uint8_t readUInt8() __attribute__((deprecated("Use template readValue<uint8_t>()")))
Read a byte value.
Definition: NimBLERemoteCharacteristic.cpp:447
uint16_t getDefHandle()
Get the handle for this characteristics definition.
Definition: NimBLERemoteCharacteristic.cpp:382
A model of remote BLE descriptor.
Definition: NimBLERemoteDescriptor.h:29
A model of a remote BLE service.
Definition: NimBLERemoteService.h:36
A model of a BLE UUID.
Definition: NimBLEUUID.h:31