bt_gatt_read only reads 22 bytes from BLE characteristic, while it should return 240 bytes

Hi,

I am trying to read characteristics from a BT device via the NRF9160DK. 
I have configured this NRF9160DK with dual-chip configuration, where NRF9160 contains the application code, and the NRF52840 chip runs the BLE HCI driver. 
The application code on the NRF9160 successfully utilizes the HCI UART interface to scan for BT devices, connect to a specific device, and read characteristics

The characteristics are read successfully, except for one char which is significantly larger in size. 
The characteristics that I can successfully read are only one or several bytes in size. 
But when I attempt to read a characteristic that should return 240 bytes, it only returns 22 bytes. 
I know that it should actually return 240 bytes because that is what the NRF connect app returns (see image), and it should according to the manufacturer of that BT device.

Is there a maximum number of bytes that the bt_gatt_read function could return in it's callback?
And is there a way to increase this limit, e.g., via the prj.conf or through code?
What happened to the remaining 218 bytes?

I am sorry for asking if this is described already in documentation.
I am still learning this SDK. and not sure where to find this information.
I have already looked at the SDK for the bt_gatt_read function and callback, which I linked above.
No maximum length is mentioned there.

I have only included the code for just the callback function as well as the prj.conf. 

static uint8_t read_cb(struct bt_conn *conn, uint8_t err,
				    struct bt_gatt_read_params *params,
				    const void *data, uint16_t length)
{
    printk("Read data of length %d\n", length);

	if (err)
	{
		printk("Read Err %d\n", err);
	}

	// << process data here >>

	return 0;
}

#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
# General config
CONFIG_NEWLIB_LIBC=y
CONFIG_ASSERT=y
CONFIG_REBOOT=y

# AT host
CONFIG_AT_HOST_LIBRARY=y

# Disable Modem traces, since we need UART1 for HCI
CONFIG_NRF_MODEM_LIB_TRACE_ENABLED=n

# Enable Bluetooth stack and libraries
CONFIG_BT=y
CONFIG_BT_H4=y
CONFIG_BT_WAIT_NOP=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DM=y
CONFIG_BT_SCAN=y
CONFIG_BT_SCAN_FILTER_ENABLE=y
CONFIG_BT_SCAN_UUID_CNT=1
CONFIG_BT_SCAN_ADDRESS_CNT=1

# Max simultaneous connections
CONFIG_BT_MAX_CONN=10

# Timeout in seconds for connecting to device
CONFIG_BT_CREATE_CONN_TIMEOUT=10

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_MAIN_STACK_SIZE=8192

# Support Floating Points in printk
CONFIG_CBPRINTF_FP_SUPPORT=y

Parents
  • You need Increase MTU or GATT long read procedure.

    uint16_t offset = 0;
    static uint8_t read_cb(struct bt_conn *conn, uint8_t err,
    				    struct bt_gatt_read_params *params,
    				    const void *data, uint16_t length)
    {
        printk("Read data of length %d\n", length);
    
    	if (err)
    	{
    		printk("Read Err %d\n", err);
    	}
    
    
        if (data != NULL) {
            offset += length;
    	    // << process data here >>
       		return BT_GATT_ITER_CONTINUE;
        } else {
            // The end of long read procedure
        		return BT_GATT_ITER_STOP;
        }
    }

Reply
  • You need Increase MTU or GATT long read procedure.

    uint16_t offset = 0;
    static uint8_t read_cb(struct bt_conn *conn, uint8_t err,
    				    struct bt_gatt_read_params *params,
    				    const void *data, uint16_t length)
    {
        printk("Read data of length %d\n", length);
    
    	if (err)
    	{
    		printk("Read Err %d\n", err);
    	}
    
    
        if (data != NULL) {
            offset += length;
    	    // << process data here >>
       		return BT_GATT_ITER_CONTINUE;
        } else {
            // The end of long read procedure
        		return BT_GATT_ITER_STOP;
        }
    }

Children
Related