Skip to content

Commit 458ae5e

Browse files
committed
Fix BLECharacteristic::readValue(...) triggering a read request after a notification/indication was received
1 parent 631f807 commit 458ae5e

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/BLECharacteristic.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,9 @@ int BLECharacteristic::readValue(uint8_t value[], int length)
170170
}
171171

172172
if (_remote) {
173-
// trigger a read if the value hasn't been updated via
174-
// indication or notification, and the characteristic is
175-
// readable
176-
if (!valueUpdated() && canRead()) {
173+
// trigger a read if the updated value (notification/indication)
174+
// has already been read and the characteristic is readable
175+
if (_remote->updatedValueRead() && canRead()) {
177176
if (!read()) {
178177
// read failed
179178
return 0;

src/remote/BLERemoteCharacteristic.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(const uint8_t uuid[], uint8_t u
3333
_value(NULL),
3434
_valueLength(0),
3535
_valueUpdated(false),
36+
_updatedValueRead(true),
3637
_valueUpdatedEventHandler(NULL)
3738
{
3839
}
@@ -148,6 +149,15 @@ bool BLERemoteCharacteristic::valueUpdated()
148149
return result;
149150
}
150151

152+
bool BLERemoteCharacteristic::updatedValueRead()
153+
{
154+
bool result = _updatedValueRead;
155+
156+
_updatedValueRead = true;
157+
158+
return result;
159+
}
160+
151161
bool BLERemoteCharacteristic::read()
152162
{
153163
if (!ATT.connected(_connectionHandle)) {
@@ -177,7 +187,6 @@ bool BLERemoteCharacteristic::read()
177187
return false;
178188
}
179189

180-
_valueUpdated = true;
181190
memcpy(_value, &resp[1], _valueLength);
182191

183192
return true;
@@ -245,6 +254,7 @@ void BLERemoteCharacteristic::writeValue(BLEDevice device, const uint8_t value[]
245254
}
246255

247256
_valueUpdated = true;
257+
_updatedValueRead = false;
248258
memcpy(_value, value, _valueLength);
249259

250260
if (_valueUpdatedEventHandler) {

src/remote/BLERemoteCharacteristic.h

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class BLERemoteCharacteristic : public BLERemoteAttribute {
4242
int writeValue(const char* value);
4343

4444
bool valueUpdated();
45+
bool updatedValueRead();
4546

4647
bool read();
4748
bool writeCccd(uint16_t value);
@@ -71,6 +72,7 @@ class BLERemoteCharacteristic : public BLERemoteAttribute {
7172
int _valueLength;
7273

7374
bool _valueUpdated;
75+
bool _updatedValueRead;
7476

7577
BLELinkedList<BLERemoteDescriptor*> _descriptors;
7678

0 commit comments

Comments
 (0)