Bluetooth Device Stops Advertising After Pairing Failures in Zephyr RTOS

Hello everyone, I have a situation where the device tries to auto connect and then stops advertising.
*** Booting Zephyr OS build v3.7.0-rc1-106-g012520d2d7e8 ***
[00:00:00.327,148] <inf> fs_nvs: 4 Sectors of 4096 bytes
[00:00:00.327,178] <inf> fs_nvs: alloc wra: 0, d18
[00:00:00.327,178] <inf> fs_nvs: data wra: 0, 430
[00:00:00.328,582] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
[00:00:00.328,613] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
[00:00:00.328,643] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 3.7 Build 0
[00:00:00.328,918] <inf> bt_hci_core: No ID address. App must call settings_load()
Bluetooth initialized
[00:00:00.330,993] <inf> bt_hci_core: Identity: D5:ED:9A:B3:35:2F (random)
[00:00:00.331,024] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x0000, manufacturer 0x05f1
[00:00:00.331,054] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0xffff
Advertising successfully started
Bluetooth authentication callbacks registered.
Connected C8:E2:65:D4:FA:57 (public)
[00:00:00.672,821] <err> bt_smp: pairing failed (peer reason 0x5)
Security failed: C8:E2:65:D4:FA:57 (public) level 1 err 5
[00:00:00.852,386] <err> bt_smp: pairing failed (peer reason 0x3)
Security failed: C8:E2:65:D4:FA:57 (public) level 1 err 4
*** Booting Zephyr OS build v3.7.0-rc1-106-g012520d2d7e8 ***
[00:00:00.327,148] <inf> fs_nvs: 4 Sectors of 4096 bytes
[00:00:00.327,178] <inf> fs_nvs: alloc wra: 0, d18
[00:00:00.327,178] <inf> fs_nvs: data wra: 0, 430
[00:00:00.328,582] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
[00:00:00.328,613] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
[00:00:00.328,643] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 3.7 Build 0
[00:00:00.328,918] <inf> bt_hci_core: No ID address. App must call settings_load()
Bluetooth initialized
[00:00:00.330,993] <inf> bt_hci_core: Identity: D5:ED:9A:B3:35:2F (random)
[00:00:00.331,024] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x0000, manufacturer 0x05f1
[00:00:00.331,054] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0xffff
Advertising successfully started
Bluetooth authentication callbacks registered.
Connected C8:E2:65:D4:FA:57 (public)
[00:00:00.672,821] <err> bt_smp: pairing failed (peer reason 0x5)
Security failed: C8:E2:65:D4:FA:57 (public) level 1 err 5
[00:00:00.852,386] <err> bt_smp: pairing failed (peer reason 0x3)
Security failed: C8:E2:65:D4:FA:57 (public) level 1 err 4
the functionality is of HoG Mouse sample with a few changes mainly changing to bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); my proj.conf is
CONFIG_BT=y
CONFIG_LOG=y
CONFIG_BT_SMP=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DIS=y
CONFIG_BT_BAS=y
CONFIG_BT_DEVICE_APPEARANCE=962
CONFIG_SAMPLE_BT_USE_AUTHENTICATION=y
CONFIG_BT_SETTINGS=y
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETLINE=y
CONFIG_BT=y
CONFIG_LOG=y
CONFIG_BT_SMP=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DIS=y
CONFIG_BT_BAS=y
CONFIG_BT_DEVICE_APPEARANCE=962
CONFIG_SAMPLE_BT_USE_AUTHENTICATION=y
CONFIG_BT_SETTINGS=y
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETLINE=y
22 Replies
melta101
melta101•4mo ago
If you need any further information to assist me, please feel free to ask!
ZacckOsiemo
ZacckOsiemo•4mo ago
Hey @32bitSaviour and I are doing a BLE live stream in another 30 mins if you want to join
melta101
melta101•4mo ago
That's nice i reaally wanted to join but currently at work Maybe add the link, and ill hop in during break session
melta101
melta101•4mo ago
Once you are free, Could you help with the above, stumbled for quite some time...
ZacckOsiemo
ZacckOsiemo•4mo ago
this link is on #projects-and-self-promotion 🙂 welcome, come to the stream and ask your questions. some of the basics that are explained may help this get clear
melta101
melta101•4mo ago
Sure That sound perfect!
melta101
melta101•4mo ago
Need some way to flash the NVS at once...
32bitSaviour
32bitSaviour•4mo ago
@melta101 since you have settings enabled in your prj.conf do you make sure to call settings_load()?
melta101
melta101•4mo ago
yes, Its called in bt_ready()
melta101
melta101•4mo ago
Major prob is even after reflashing for the particular module, it gives the same error, meaning, i would need to 1st erase all the stuffs in settings, and then try
melta101
melta101•4mo ago
as per my understanding
32bitSaviour
32bitSaviour•4mo ago
You need to call it after the bt_enable() API call so if you have a bt_ready callback you can do it inside there in case of success.
melta101
melta101•4mo ago
it is written in this way,
bt_enable(bt_ready);
bt_enable(bt_ready);
melta101
melta101•4mo ago
if it fails, i get a notifs
melta101
melta101•4mo ago
logs suggest, i got it initialized, starts advertising, then proceed to automatically try connecting to the address
32bitSaviour
32bitSaviour•4mo ago
And at that point you call settings_load? You can also error check it to make sure it loads successfully.
melta101
melta101•4mo ago
i have also faced this another set of problem i sometimes, want my peripherals to to connect without password what i do normally is not call the bt_conn_auth_cb struct such as passkey display or entry trying to do this, i sometimes get it to work,(passwordless connection) other times, it doesnt (security change error)
melta101
melta101•4mo ago
what is the ideal way to get the passwordless connection to work
32bitSaviour
32bitSaviour•4mo ago
You can set empty callbacks in the struct and passkey_entry to NULL. That will ensure your BLE connection uses the Just Works pairing method.
melta101
melta101•4mo ago
tried that and got this
Advertising successfully started
Connected 94:8A:C6:7D:A4:76 (public)
Security failed: 94:8A:C6:7D:A4:76 (public) level 1 err 4
Error: Authentication requirement mismatch with 94:8A:C6:7D:A4:76 (public)
Disconnected from 94:8A:C6:7D:A4:76 (public) (reason 0x13)
Advertising successfully started
Connected 94:8A:C6:7D:A4:76 (public)
Security failed: 94:8A:C6:7D:A4:76 (public) level 1 err 4
Error: Authentication requirement mismatch with 94:8A:C6:7D:A4:76 (public)
Disconnected from 94:8A:C6:7D:A4:76 (public) (reason 0x13)
32bitSaviour
32bitSaviour•4mo ago
GitHub
zephyr/include/zephyr/bluetooth/hci_types.h at ad70ff7b9d5dbd342f53...
Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures. - zephyrproject-rtos/zephyr
melta101
melta101•4mo ago
Sorry for the delay in reply, Just reached back Yea, for error code 4, It means auth requirement mismatch From what I see, Seems like a smart phone cannot connect with level 1 security
Want results from more Discord servers?
Add your server