How to read advertising BLE devices' name?

I've google the heck out of this, but I feel like I'm missing something because there are zero results.

I am developing a BLE central device, and the program is supposed to scan for advertising BLE devices, and list their address and name. Since the program is based off the "BLE Central" example, I have no issue reading their addresses, however, I cannot figure out how to read device names (e.g. "Zephyr BLE Module").

I know the BLE devices are advertising their names because I can see their names when I use the nRF Connect bluetooth app, but I want to be able to see their names through my own program, and print it to the console.

If it matters, the peripheral device is using the "BLE Peripheral" example.

  • You could not find any names at all? 

    None, and there are at least 4 bluetooth devices advertising their name nearby.

    do you have another dk you can set up as an peripheral? 

    My central device is an nRF52840 DK, and I've been using an nRF52840 MDK Dongle as a peripheral.

    In case this helps, here's what the prj.conf and CMakeLists.txt files look like:

    CONFIG_BT=y
    CONFIG_BT_CENTRAL=y

    # SPDX-License-Identifier: Apache-2.0
    
    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(central)
    
    target_sources(app PRIVATE
      src/main.c
    )
    
    zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)

  • Do you advertise device name from your peripheral? I tested with the peripheral_uart example and I could find it without any problems using the code I have you, 

    Regards

    Runar

  • Do you advertise device name from your peripheral?

    Yes, but also so do the other devices around me.

    I tried with a brand new project, totally clean, same issue.

    Device found: C6:65:16:45:84:67 (public) (RSSI -75)
    Device found:
    Connected: C6:65:16:45:84:67 (public)
    Disconnected: C6:65:16:45:84:67 (reason 0x3e)
    Scanning successfully started

    After uploading the "peripheral_uart" example to the peripheral device, the name now DOES show up in the terminal on the central device DK. However, other devices still do not, including the "peripheral" (without uart) example.

    Why is that? I want to use the "peripheral" example, not the "peripheral_uart". What is causing this issue?

  • Hi, 

    Can you try to change "start_scan" to:

     

    err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found);
    
    to
    
    err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, device_found);

    and

    add update device_found with this:

    	if (type != BT_GAP_ADV_TYPE_ADV_IND &&
    	    type != BT_GAP_ADV_TYPE_ADV_DIRECT_IND &&
    		type != BT_GAP_ADV_TYPE_SCAN_RSP  ) {
    		return;
    	}

    Regards

    Runar

  • Just tried this, but no change to the result.

    "peripheral_uart" to "central" shows the name.

    "peripheral" to "central" does not show the name.

Related