user3656743
user3656743

Reputation: 31

Is there a way to get a notification or callback when an indication from the peripheral has been acknowledged by the central with Nimble Bluetooth LE?

I am using Nimble on ESP32-S3. This chip only has BT LE. I am trying to send/receive bulk data (which of course isn't really suited for BT LE, but does seem to work nevertheless).

The problem is, when to send the next chunk of data to the central. When I send two indications in short succession I am getting an "out of resources" error from Nimble. No matter what configuration I do related to mbufs and memory reservation, this behaviour remains. I actually have no problem with that, it's just that I need to know when I can send the next chunk [ble_gatts_indicate_custom with an os_mbuf). My now working solution is to just try until it succeeds (with a short delay of course). And of course that's ugly.

I am aware that there is an event callback for sent notifications/indications (BLE_GAP_EVENT_NOTIFY_TX) but it doesn't help here. It turns out this callback is called from within the function ble_gatts_indicate_custom itself (as proven by stack trace and Nimble source). So it doesn't say anything about the status of the indication having been sent or acknowledged.

With debug log on, I get some information from Nimble whenever the indication actually has been acknowledged, so apparently Nimble knows. Which is what I'd expect.

So the question is: is there a way that Nimble can share it's knowledge that my indication was acknowledged by the central with my code (calling Nimble).

Thanks!

EDIT: This kind of debug logs:

I (16913) NimBLE: GATT procedure initiated: indicate; 
I (16913) NimBLE: att_handle=16

this is where I'd like to have a notification/callback to my code.

EDIT: this my characteristics definition:

static const struct ble_gatt_svc_def gatt_definitions[] =
{
    {
        .type = BLE_GATT_SVC_TYPE_PRIMARY,
        .uuid = BLE_UUID16_DECLARE(SERVICE_HANDLE),
        .characteristics = (struct ble_gatt_chr_def[])
        {
            {
                .uuid = BLE_UUID16_DECLARE(CHARACTERISTICS_HANDLE),
                .access_cb = gatt_event,
                .val_handle = &attribute_handle,
                .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_NOTIFY,
            },
            {
                0,
            }
        },
    },
    {
        0,
    },
};

I added my notification callback function here (gatt_event), it's called when a.o. when an indication is being sent but there is no notification for an indication having been acknowledged by the central.

Upvotes: 1

Views: 294

Answers (0)

Related Questions