taks / esp32-nimble

A wrapper for the ESP32 NimBLE Bluetooth stack.
Apache License 2.0
118 stars 35 forks source link

Why is the value of a characteristic automatically changed but notify is not automatically called? #71

Closed ChocolateLoverRaj closed 9 months ago

ChocolateLoverRaj commented 9 months ago

I connected to an ESP32-C3 BLE server and there is a read, write, and notify characteristic. I enabled notifications on the first device and then changed the value with the second device. The first device did not get a notification. When I read the value with the first device manually, I saw the updated value. When I added notify() to the code on write, notifications worked as expected.

taks commented 9 months ago

The current behavior is expected. Notify is not automatically invoked so that users can use it when they want to.

However, I did not realize that it is a hard to call notify when writing from the outside. So, I added notify funciton to OnWriteArgs so that you can easily notify as follows.

characteristic
  .lock()
  .on_write(|args| {
    args.notify();
  });