embassy-rs / nrf-softdevice

Apache License 2.0
269 stars 80 forks source link

Writing 'notify_value' fast causes values to not send #273

Closed Gibbz closed 3 months ago

Gibbz commented 3 months ago

I'm writing to gatt_server::notify_value every minute with a few different data points from different threads. Ive noticed that as my threads are all sending their messages very close together, it causes no messages to be sent.

I also have the same situation when I receive data, and try to send return a notify that also does not work unless I use a delay. If I send data directly after receiving, it fails.

Ive noticed there is a deferred read/write and on_notify_tx_complete. Do I need to make my own async que with mutex to work around this issue?

Is there a way around this issue? Possibly some setting in the bluetooth config?

alexmoon commented 3 months ago

This is expected behavior, as documented by Nordic. Generally speaking, GATT characteristics are not designed as an event system or communication channel. Notifications are intended to provide the current value of the characteristic, which means that dropped or coalesced notifications are considered normal. You can use indications instead of notifications to ensure reliable receipt by the central; it will still be up to you to ensure only a single indication/notification is in-flight at a time.