This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to disable Bluetooth ?

Hello,

I'm looking to disable the Bluetooth in the ledButtonDemo,. In the led_write_handler, I've replaced the code by :

if(led_state == 0) { sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); sd_ble_gap_adv_stop(); NRF_RADIO->TASKS_DISABLE=1; nrf_gpio_pin_clear(24); }

else { nrf_gpio_pin_set(24); }

But with the dongle, I'm still seeing the device "ledButtonDemo", and I'm able to connect it, and to change the settings.

Is there a mistake in my code ?

I used this topic to create my code : devzone.nordicsemi.com/.../

Thanks in advance !

  • I'm not sure exactly what is happening here, but you shouldn't do NRF_RADIO->TASKS_DISABLE=1; as seen from the comment of Ole Bauck in the linked question.

    There is also no point in stopping advertising if you aren't advertising.

    I'm guessing that either an error is returned somewhere and because of that you get a reset. It seems you are not using APP_ERROR_CHECK() so that may not be the reason.

    Are you getting the BLE_GAP_EVT_DISCONNECTED event? Maybe you have an advertising_start(); in on_ble_evt()?

    If you are a peripheral, the radio is "disabled" or not used, as long as you are not in a connection and you are not advertising.

  • Ok, I'll test to add APP_ERROR_CHECK, and I will tell you if it changes something !

    In on_ble_evt(), and particularly in the case BLE_GAP_EVT_DISCONNECTED, there "advertising_start();", so do I have to delete this line ?

    So, to disable Bluetooth, I have to call this line : on_ble_evt(BLE_GAP_EVT_DISCONNECTED); ?

  • After you have called sd_ble_gap_disconnect() you will get the BLE_GAP_EVT_DISCONNECTED event when you are actually disconnected. Have a look at this MSC. You can just remove advertising_start() and there will be noe Bluetooth activity on the radio.

Related