Problem: I am following on Bluetooth Fundamental Course on Nordic Academy webpage. I successfully advertising BLE with non-connectable option. But change adv_param to BT_LE_ADV_OPT_CONN cause error as following:
*** Booting nRF Connect SDK v3.0.2-89ba1294ac9b ***
*** Using Zephyr OS v4.0.99-f791c49f492c ***
[00:00:02.008,972] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision:
89 9a 50 8a 95 01 9c 58 fc 39 d2 c1 10 04 ee 02 |..P....X .9......
64 ce 25 be |d.%.
[00:00:02.039,459] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
[00:00:02.047,210] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
[00:00:02.053,741] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 137.20634 Build 2617349514
[00:00:02.066,162] <inf> bt_hci_core: Identity: C3:28:9F:CE:96:D8 (random)
[00:00:02.073,455] <inf> bt_hci_core: HCI: version 6.0 (0x0e) revision 0x10f3, manufacturer 0x0059
[00:00:02.082,824] <inf> bt_hci_core: LMP: version 6.0 (0x0e) subver 0x10f3
[00:00:02.090,179] <inf> main: BLE initialized
[00:00:02.095,336] <wrn> bt_hci_core: opcode 0x2006 status 0x11
ASSERTION FAIL [err == 0] @ CMAKE_SOURCE_DIR/src/main.c:82
Advertising failed to start (err = -5)
This is my code in main.c:
/* Enable and initialize Bluetooth */
err = bt_enable(NULL);
__ASSERT(err == 0, "BLE init failed (err = %d)\n", err);
LOG_INF("BLE initialized");
/* BLE advertising */
err = bt_le_adv_start(adv_param, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
__ASSERT(err == 0, "Advertising failed to start (err = %d)\n", err);
LOG_INF("Advertising successfully");
This is adv_param struct:
static const struct bt_le_adv_param *adv_param = BT_LE_ADV_PARAM( (BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_USE_IDENTITY), /* Connectable advertising and use identity address */ 800, /* Min Advertising Interval 500ms (800*0.625ms) */ 801, /* Max Advertising Interval 500.625ms (801*0.625ms) */ NULL); /* Set to NULL for undirected advertising */
static const struct bt_data ad[] = {
/* STEP 3.1 - Set the flags and populate the device name in the advertising packet */
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};
static const struct bt_data sd[] = {
/* STEP 3.2.2 - Include the 16-bytes (128-Bits) UUID of the LBS service in the scan response packet */
BT_DATA_BYTES(BT_DATA_UUID128_ALL,
BT_UUID_128_ENCODE(0x00001523, 0x1212, 0xefde, 0x1523, 0x785feabcd123)),
};
CONFIG_DEBUG=y CONFIG_LOG_MODE_IMMEDIATE=y CONFIG_ASSERT=y CONFIG_ASSERT_ON_ERRORS=y # Bluetooth CONFIG_BT=y CONFIG_BT_DEVICE_NAME="Nordic Device" CONFIG_BT_MAX_CONN=2 # Reset pin # CONFIG_GPIO_AS_PINRESET=y # Enable GPIO CONFIG_GPIO=y # Enable UART CONFIG_SERIAL=y # Enable console CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_LOG=y