No device found with bt_le_scan_start and observer

Dear,

I am using nRF5340 and I am trying to scan devices around me. With the example observer my device founds other devices around me, but when I use the same configuration and the same functions into my project the device doesn't find anything. The code is the same, exactly the same but I can't see anything.

The prj.conf is

#Peripherals
CONFIG_GPIO=y
CONFIG_SPI=y

CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

CONFIG_PRINTK=y


# Bootloader
CONFIG_BOOTLOADER_MCUBOOT=y

# Bluetooth configuration
CONFIG_BT=y
#CONFIG_BT_PERIPHERAL=y
#CONFIG_BT_DEVICE_NAME="Test"
#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_CENTRAL=y
#CONFIG_BT_SCAN=y
CONFIG_BT_OBSERVER=y

# Other 
CONFIG_MAIN_STACK_SIZE=2048

CONFIG_LOG=y

And the code is:

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>


#if (APP_DEBUG_ON == 1)
#include <zephyr/sys/printk.h>
#endif

#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)

static void deviceFound (const bt_addr_le_t *addr, 
                         int8_t rssi, 
                         uint8_t type,
                         struct net_buf_simple *buf)
{
    char dev[BT_ADDR_LE_STR_LEN];

    // if (type == BT_GAP_ADV_TYPE_ADV_SCAN_IND)
    // {
        bt_addr_le_to_str(addr, dev, sizeof(dev));
        printk("[DEVICE]: %s, AD evt type %u, AD data len %u, RSSI %i\n",dev, type, buf->len, rssi);
    // }


}

void Bluetooth_init (void)
{
    int err = 0;

    err = bt_enable(NULL);
    if (err) 
    {
#if (APP_DEBUG_ON == 1)
        printk("ERROR: Bluetooth init failed (err %d)\n", err);
#endif
        goto bluetooth_init_error;
    }

#if (APP_DEBUG_ON == 1)
    printk("BLUETOOTH0: Bluetooth initialized\n");
#endif

	struct bt_le_scan_param scanParam = 
    {
        .type       = BT_LE_SCAN_TYPE_PASSIVE,
        .options    = BT_LE_SCAN_OPT_FILTER_DUPLICATE,
        .interval   = BT_GAP_SCAN_FAST_INTERVAL,
        .window     = BT_GAP_SCAN_FAST_WINDOW,
    };

    err = bt_le_scan_start(&scanParam, deviceFound);
    if (err) 
    {
#if (APP_DEBUG_ON == 1)
        printk("ERROR: Scanning failed to start (err %d)\n", err);
#endif
        goto bluetooth_init_error;
    }
#if (APP_DEBUG_ON == 1)
    printk("BLUETOOTH0: Scanning successfully started\n");
#endif

bluetooth_init_error:
    if (err)
    {
        // TODO
    }
}

The output log is:

BLUETOOTH0: Bluetooth initialized
BLUETOOTH0: Scanning successfully started

Where is it the error? Haw can I debug this issue?

Thanks

Marco

  • Hi Simon, 

    the observer example works fine.

    My project started from the "hello world" example doesn't work. I put into the prj.conf all the configurations needed (like in the observer example), and other configurations for "mcuboot" and "sdcard", but the scanning doesn't work. You can see the configuration in the first post.

    I don't know what I do in a different way from the observer example!

    Thanks

    Best regards

    Marco

  • Hi Marco

    Can you try enabling CONFIG_BT_HCI=y as well in your config file. I'm not quite sure why you're not able to scan as expected with this implementation, might be because I'm missing insight, but your code builds fine in hello_world on our end. What Bluetooth controller are you using on the NET core? The Zephyr BLE controller or Nordic's SoftDevice controller?

    Best regards,

    Simon

  • Hi Simon,

    I added the row into the config file. I put the start scan a little bit earlier than before and now somethings came up as you can see in the image (the black side is the app core, the white side is the network core)... but after some seconds no more can be found... nothing.

    Just to be sure of this behaviour I switched off some beacons,  start the scan, and now switch on the beacons.. and it doesn't show these devices.  

    I am sure that the app core is not blocked in a while loop or in a fail, because it does other things!

    Best regards

    Marco

  • Hi Marco,

    Simon is out of office and I will substitute for him here.

    From your description and your log, does the scan stop working after mere five seconds?

    To ensure the net core is also working, could you also setup another BLE activities running in parallel with scanning and get the log? Perhaps the easiest is a beacon broadcasting without a timeout.

    Best regards,

    Hieu

  • Hi Hieu,

    nice to meet you. 

    Yes, the scan stops working after mere five seconds.

    For the test: can you suggest me the code to add this functionality?

    Thanks

    Marco

Related