This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

duplicate callbacks, NRF_ERROR_BUSY on discovery.

Hi. I have two codebases here:

  1. A peripheral application on an nRF51822 using SDK 12.2.0, SD 130. It has two vendor-specific services: the Nordic UART service and one of my own.

  2. A central application on an nRF51 dongle using the pc-ble-driver and running on Windows, written in C. I can't use the Node.js or Python bindings for the pc-ble-driver. Because I'm building this on Windows, I also can't use the BLE DB discovery library from the SDK. I've used the heart rate collector example central from the pc-ble-project as a starting point.

Here's the console output for the central. [edit] Console output now edited to show the handle range for each call.

Expecting to find nRF dongle on port COM4.
Scanning for BLE peripheral with MAC address F802D8BD76AC.
Info: Successfully opened COM4. Baud rate: 115200. Flow control: none. Parity: n
one.

Status: 6, message: Target Reset performed
Status: 7, message: Connection active
Scan started.
Connecting to 0xF802D8BD76AC.
Connected.
Discovering Nordic UART Service.
Got service discovery response.
Discovered service. UUID: 0x0001, start handle: 0x000F, end handle: 0x0014
  Discovering characteristics. Handle range: 0x000F to 0x0014.
  Characteristic handle: 0x0010, UUID: 0x0003 (1 of 1).
  NUS RX.
  Discovering characteristics. Handle range: 0x0012 to 0x0014.
  Characteristic handle: 0x0013, UUID: 0x0002 (1 of 1).
  NUS TX.
  Discovering descriptors. Handle range: 0x000F to 0x0014.
  Descriptor handle: 0x000F, UUID: 0x2800 (1 of 2)
  Descriptor handle: 0x0010, UUID: 0x2803 (2 of 2)
  Discovering descriptors. Handle range: 0x0010 to 0x0014.
  Descriptor handle: 0x0011, UUID: 0x0003 (1 of 1)
  Discovering descriptors. Handle range: 0x0012 to 0x0014.
  Descriptor handle: 0x0012, UUID: 0x2902 (1 of 2)
  CCCD (nus).
  Descriptor handle: 0x0013, UUID: 0x2803 (2 of 2)
  Discovering descriptors. Handle range: 0x0013 to 0x0014.
  Descriptor handle: 0x0014, UUID: 0x0002 (1 of 1)
Discovering Bike Tracker Service.
Got service discovery response.
Discovered service. UUID: 0x1523, start handle: 0x0015, end handle: 0x001E
  Discovering characteristics. Handle range: 0x0015 to 0x001E.
  Characteristic handle: 0x0016, UUID: 0x1525 (1 of 1).
  BTS test state.
  Discovering characteristics. Handle range: 0x0018 to 0x001E.
  Characteristic handle: 0x0018, UUID: 0x1526 (1 of 1).
  Discovering characteristics. Handle range: 0x001A to 0x001E.
  Characteristic handle: 0x001A, UUID: 0x1527 (1 of 1).
  BTS log.
  Discovering characteristics. Handle range: 0x001C to 0x001E.
  Characteristic handle: 0x001D, UUID: 0x1529 (1 of 1).
  Discovering descriptors. Handle range: 0x0015 to 0x001E.
  Descriptor handle: 0x0015, UUID: 0x2800 (1 of 2)
  Descriptor handle: 0x0016, UUID: 0x2803 (2 of 2)
  Discovering descriptors. Handle range: 0x0016 to 0x001E.
  Discovering descriptors. Handle range: 0x0017 to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x0017 to 0x001E.
  Descriptor handle: 0x0016, UUID: 0x2803 (1 of 1)
  Discovering descriptors. Handle range: 0x0017 to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x0017 to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x0017 to 0x001E.
  Descriptor handle: 0x0017, UUID: 0x1525 (1 of 1)
  Discovering descriptors. Handle range: 0x0018 to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x0018 to 0x001E.
  Descriptor handle: 0x0017, UUID: 0x1525 (1 of 1)
  Discovering descriptors. Handle range: 0x0018 to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x0018 to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x0018 to 0x001E.
  Descriptor handle: 0x0018, UUID: 0x2803 (1 of 1)
  Discovering descriptors. Handle range: 0x0019 to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x0019 to 0x001E.
  Descriptor handle: 0x0018, UUID: 0x2803 (1 of 1)
  Discovering descriptors. Handle range: 0x0019 to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x0019 to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x0019 to 0x001E.
  Descriptor handle: 0x0019, UUID: 0x1526 (1 of 1)
  Discovering descriptors. Handle range: 0x001A to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x001A to 0x001E.
  Descriptor handle: 0x0019, UUID: 0x1526 (1 of 1)
  Discovering descriptors. Handle range: 0x001A to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x001A to 0x001E.
  Descriptor handle: 0x001A, UUID: 0x2803 (1 of 1)
  Discovering descriptors. Handle range: 0x001B to 0x001E.
  Descriptor handle: 0x001A, UUID: 0x2803 (1 of 1)
  Discovering descriptors. Handle range: 0x001B to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x001B to 0x001E.
  Descriptor handle: 0x001B, UUID: 0x1527 (1 of 1)
  Discovering descriptors. Handle range: 0x001C to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x001C to 0x001E.
  Descriptor handle: 0x001B, UUID: 0x1527 (1 of 1)
  Discovering descriptors. Handle range: 0x001C to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x001C to 0x001E.
Error: sd_ble_gattc_descriptors_discover(): 0x11.
NRF_ERROR_BUSY
  Discovering descriptors. Handle range: 0x001C to 0x001E.
  Descriptor handle: 0x001C, UUID: 0x2902 (1 of 2)
  CCCD (bts).
  Descriptor handle: 0x001D, UUID: 0x2803 (2 of 2)
Writing to NUS TX CCCD to enable notifications.
Error: Busy. Slow down.
  Descriptor handle: 0x001C, UUID: 0x2902 (1 of 2)
  CCCD (bts).
  Descriptor handle: 0x001D, UUID: 0x2803 (2 of 2)

First, why are there so many duplicate callbacks for characteristic and descriptor discovery? Every time a callback completes, I increment the start handle and call the discovery function again, until the start handle meets the end handle. I'd expect to get only one callback per characteristic and descriptor.

Second, why am I getting NRF_ERROR_BUSY so much? I always wait for the callback to come through ble_evt_dispatch() before I make the next call.

Here's main.c:

adapter_t * m_adapter = NULL;
char * m_peripheral_mac_address = NULL;
char * m_test_state_name = NULL;

int main(int argc, char * argv[])
{
    uint32_t error_code;
    char * serial_port;
    uint8_t cccd_value = 0;
	bool bts_discovery_started = false;
	bool test_started = false;

	if (argc != 4)
	{
		printf("Usage: biketracker_test_central.exe <serial port> <BLE MAC address> <test state>\n");
		printf("   eg: biketracker_test_central.exe COM4 D7:26:B0:C5:88:20 pcba\n");
		printf("   or: biketracker_test_central.exe COM4 D7:26:B0:C5:88:20 system\n");
		fflush(stdout);
		return APP_ERROR_INVALID_ARGS;
	}

	serial_port = argv[1];
	m_peripheral_mac_address = argv[2];
	m_test_state_name = argv[3];

    printf("Expecting to find nRF dongle on port %s.\n", serial_port);
	printf("Scanning for BLE peripheral with MAC address %s.\n", m_peripheral_mac_address);
    fflush(stdout);

    m_adapter = adapter_init(serial_port);
    sd_rpc_log_handler_severity_filter_set(m_adapter, SD_RPC_LOG_INFO);
    error_code = sd_rpc_open(m_adapter, status_handler, ble_evt_dispatch, log_handler);

    if (error_code != NRF_SUCCESS)
    {
        printf("Failed to open nRF BLE Driver. Error code: 0x%02X\n", error_code);
        fflush(stdout);
        return error_code;
    }

    error_code = ble_stack_init();

    if (error_code != NRF_SUCCESS)
    {
		printf("Failed to init BLE stack. Error code: 0x%02X\n", error_code);
		fflush(stdout);
        return error_code;
    }

    error_code = ble_options_set();

    if (error_code != NRF_SUCCESS)
    {
		printf("Failed to set BLE options. Error code: 0x%02X\n", error_code);
		fflush(stdout);
        return error_code;
    }
    
    error_code = start_scan();

    if (error_code != NRF_SUCCESS)
    {
		printf("Failed to start scan. Error code: 0x%02X\n", error_code);
		fflush(stdout);
        return error_code;
    }

	while (!connected())
	{
		// Wait here for a connection.
	}

	// Discover services.
	discover_service_nus();
	discover_service_bts();

	// Start the test.
	while (!test_done())
	{
		if (!test_started)
		{
			test_started = true;
			error_code = start_test(m_test_state_name);

			if (error_code != NRF_SUCCESS)
			{
				printf("Failed to start test. Error code: 0x%02X\n", error_code);
				close();
				return error_code;
			}
		}
	}

	printf("Test done.\n");
	close();
	return NRF_SUCCESS;
}

And the central code (apologies for the length):

[edit]

Adding source as an attachment:

ble_central.c

Adding nRF-Sniffer capture:

bike-tracker_pc_ble_driver-discovery.pcapng

Parents Reply Children
No Data
Related