zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.55k stars 6.46k forks source link

Cant disable bluetooth for BLE peripheral after connection with Central #50874

Closed vChavezB closed 1 year ago

vChavezB commented 1 year ago

Describe the bug I have been trying to disconnect a peripheral itself from a BLE Central but I get back error values from the api bt_disableand bt_conn_disconnect

Target platform: NRF52833 DK

To Reproduce

use project peripheral_hr

https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/bluetooth/peripheral_hr

and replace main.c with these modifications

https://github.com/vChavezB/peripheral_disconnect/blob/main/main.c

Build and flash

Expected behavior Peripheral should disconnect from Central

Logs and console output

*** Booting Zephyr OS build v3.0.99-ncs1  ***
[0Bluetooth initialized
Advertising successfully started
0:00:00.004,150] <inf> sdc_hci_driver: SoftDevice Controller build revision:
                                         33 78 2a 18 20 f5 61 61  a6 8b 77 60 62 83 39 2a |3x*. .aa ..w`b.9*
                                         7c f1 14 e4                                      ||...
[00:00:00.007,568] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
[00:00:00.007,598] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
[00:00:00.007,629] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 51.10872 Build 1643454488
[00:00:00.008,941] <inf> bt_hci_core: Identity: FE:4C:08:6B:72:E8 (random)
[00:00:00.008,941] <inf> bt_hci_core: HCI: version 5.3 (0x0c) revision 0x1136, manufacturer 0x0059
[00:00:00.008,972] <inf> bt_hci_core: LMP: version 5.3 (0x0c) subver 0x1136
disconnect err -128
disable err -134
vChavezB commented 1 year ago

Now I am able to disconnect the peripheral, forgot to add the correct reason in the disconnect API

BT_HCI_ERR_REMOTE_USER_TERM_CONN

Now I need to check why disabling the bluetooth peripheral with bt_disable does not return 0.

Edit: Seems the function is unsupported for the NRF52833 DK