Questions about bt_gatt_read_params structure and bt_gatt_read callback function

Hi,

I’m working on loading batch data from a BLE server using SDK version 2.8.0 with the nRF9161-DK hardware, and I’ve encountered a couple of issues.

  1. Different Results Based on bt_gatt_read_params Initialization: When I initialize the bt_gatt_read_params structure as shown in the first example, my read_data callback only reads 5 bytes, which I can’t map to the attribute’s data. However, when I initialize the structure as shown in the second example, I can read most of the attribute’s data (but not all of it, which I’ll address in my second question).

    Why do these two initialization methods produce such different results?

  2. Issue with bt_gatt_read Callback: In my second scenario, the read_data() callback reads less data than the attribute contains. I understand that I need to return BT_GATT_ITER_CONTINUE to continue reading, but this doesn't seem to work. The next iteration does not continue to read any additional data.

    What am I doing wrong in handling this continuation of data reading?

Thanks for your time and help!

Allan

Example 1:

    const struct bt_gatt_dm_attr *attr = bt_gatt_dm_char_by_uuid(dm, BT_UUID_ATR1);
    if (attr) {
        read_params.func = read_data;
        read_params.handle_count = 1;
        read_params.single.handle = attr->handle;
        read_params.single.offset = 0;

        bt_gatt_read(bt_gatt_dm_conn_get(dm), &read_params);
    }

Example 2:

    const struct bt_gatt_dm_attr *attr = bt_gatt_dm_char_by_uuid(dm, BT_UUID_ATR1);
    if (attr) {
        read_params.func = read_data;
        read_params.handle_count = 0;
        read_params.single.offset = 0;
        read_params.by_uuid.start_handle = attr->handle;
        read_params.by_uuid.end_handle = attr->handle;
        read_params.by_uuid.uuid = BT_UUID_ATR1;

        bt_gatt_read(bt_gatt_dm_conn_get(dm), &read_params);
    }

Related