arduino-libraries / ArduinoBLE

ArduinoBLE library for Arduino
GNU Lesser General Public License v2.1
315 stars 205 forks source link

Central is notified when it changes characteristic value #144

Open arkadiuszmarszalek opened 3 years ago

arkadiuszmarszalek commented 3 years ago

When we use ArduinoBLE (1.1.3) as Peripheral device it notifies subscribed Central of characteristic value change, even if the write came from Central itself.

notification-fix.patch.zip

Additional context

Additional reports

cbrunschen commented 1 year ago

There is a set of fairly popular BLE to Serial adapters from DSD Tech (https://www.deshide.com/) which use a service with UUID FFE0 and a single characteristic FFE1 for both reading and writing data.

I tried to implement the same sort of behaviour on an ESP32. With the Espressif BLE libraries, this is straightforward. Trying to implement the same with ArduinoBLE echoes back everything that the connected Central sends to the ESP32, because of this very issue: the Central is notified of the data that it has just written to the ESP32.

This patch would fix that.

marcosinigaglia commented 12 months ago

Is there any news about it?

loginov-rocks commented 3 months ago

I also faced the same problem when using the same characteristic for both writing and notifying using this library:

BLEService myService("ffe0");
BLECharacteristic myCharacteristic("ffe1", BLERead | BLEWriteWithoutResponse | BLENotify, 20);

I assumed, which seems wrong, that BLEWriteWithoutResponse is supposed to avoid echoing. Interestingly, the ESP32 BLE library works without echoing the value written.

Can be reproduced with https://github.com/loginov-rocks/BluetoothTerminal/blob/b39badb5acc7e6a85dbd4986dab9d37bb2ca9fab/src/main.cpp together with the Web Bluetooth Terminal app. And here's implementation using the ESP32 BLE library, which works seamlessly.

Screenshots attached, for every "idle" message the code sends a "Test" message that can be seen in the web app, but echoes what was sent from the web app:

Screenshot 2024-08-14 at 10 13 04 PM Screenshot 2024-08-14 at 10 13 10 PM

I appreciate any ideas on how that can be avoided!

loginov-rocks commented 2 months ago

Hey guys, checking if there is anything new about this one? Any ideas on how to avoid?