Enable the Bluetooth radio

It's necessary to turn on the Bluetooth radio to use the Bluetooth APIs.

The user can turn on the Bluetooth radio from the Settings screen: System Settings > Network Connections > Bluetooth. Your application can use the Bluetooth APIs to check the status of the Bluetooth radio and to turn it on if needed. Changing the Bluetooth settings using the APIs will update the settings on the Bluetooth screen.

  1. Initialize the device.
  2. Enable the Bluetooth radio by calling bt_ldev_set_power(true). When the Bluetooth radio is successfully turned on, a BT_EVT_RADIO_INIT event is sent. You can check for this event in the callback you registered during initialization.
  3. If you want to set your device to be discoverable, call bt_ldev_set_discoverable() and pass in the preferred discoverable mode. Setting the local device to discoverable allows other Bluetooth enabled devices to find and connect to it. The discoverable modes are defined in bt_discoverable_t. When the discoverable mode is changed, the BT_EVT_ACCESS_CHANGED event is sent. Check for this event in your callback to make sure that the mode has changed.
The following code sample demonstrates how to enable the Bluetooth radio and set the local device to be discoverable:
if (!bt_ldev_get_power()) {
    bt_ldev_set_power(true);
}
if (bt_ldev_get_discoverable() != BT_DISCOVERABLE_GIAC) {
    bt_ldev_set_discoverable(BT_DISCOVERABLE_GIAC);
}