Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setValue() notifies twice #335

Open
vovagorodok opened this issue Dec 10, 2023 · 2 comments
Open

setValue() notifies twice #335

vovagorodok opened this issue Dec 10, 2023 · 2 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@vovagorodok
Copy link

In https://github.com/vovagorodok/ArduinoBleOTA/blob/main/src/ArduinoBleOtaClass.cpp:

BLECharacteristic txCharacteristic(BLE_OTA_CHARACTERISTIC_UUID_TX, BLERead | BLENotify, BLE_OTA_MAX_ATTR_SIZE);
...
txCharacteristic.setValue(data, length);

notifies twice about written value.
Checked on esp32dev and nano_33_iot

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Dec 11, 2023
@vovagorodok
Copy link
Author

Can't find the reason in ArduinoBLE code. Any idea why it happens? In the same scenario with NimBLE-Arduino lib I have one notification. With this issue I can't implement ArduinoBleOTA lib correctly

@osemenyuk-114
Copy link

osemenyuk-114 commented Feb 19, 2024

Hi! I faced a similar issue. After some investigations, I suppressed echoing data back to the client.
To implement this change you need to add BLEWriteWithoutResponse to the BLE Characteristics permissions and update code for void BLELocalCharacteristic::writeValue(BLEDevice device, const uint8_t value[], int length) function in src/local/BLELocalCharacteristic.cpp file.

--- a/src/local/BLELocalCharacteristic.cpp
+++ b/src/local/BLELocalCharacteristic.cpp
@@ -223,7 +223,17 @@ void BLELocalCharacteristic::writeValue(BLEDevice device, const uint8_t value[],
 {
   _written = true;

-  writeValue(value, length);
+  if (_properties & BLEWriteWithoutResponse) {
+    _valueLength = min(length, _valueSize);
+    memcpy(_value, value, _valueLength);
+
+    if (_fixedLength) {
+      _valueLength = _valueSize;
+    }
+  }
+  else {
+    writeValue(value, length);
+  }

   if (_eventHandlers[BLEWritten]) {
     _eventHandlers[BLEWritten](device, BLECharacteristic(this));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

3 participants