Search for remote devices

You can scan for Bluetooth enabled devices and retrieve information about discovered devices.

To perform a scan:
  1. Initialize the device.
  2. Make sure the Bluetooth radio is on.
  3. Scan for Bluetooth devices by calling bt_disc_start_inquiry().
  4. Retrieve discovered devices by calling bt_disc_retrieve_devices().
The following code sample demonstrates how to scan for Bluetooth devices and retrieve information from discovered devices.
// Scan for Bluetooth devices nearby.
bt_disc_start_inquiry(BT_INQUIRY_GIAC);
delay(5);
// Cancel the scan since we should have what we need by now.
bt_disc_cancel_inquiry();

// Retrieve information on discovered devices.
bt_remote_device_t *next_remote_device = 0;

bt_remote_device_t **remote_device_array = 
        bt_disc_retrieve_devices(BT_DISCOVERY_CACHED, 0);
if (remote_device_array) {
    for (int i = 0; (next_remote_device = remote_device_array[i]); ++i) {
        char device_name[128];
        char device_addr[128];
        int device_class = -1;
        const int bufferSize = sizeof(device_name);

        // Get the friendly name of the remote device. The
        // friendly name is a string value that makes it easy
        // to identify the device.
        if (bt_rdev_get_friendly_name(next_remote_device, 
                                      device_name, bufferSize) != 0) {
            // handle error
            ...
        }    
        // Retrieve the MAC address of the remote device.
        if (bt_rdev_get_address(next_remote_device, 
                                device_addr) != 0) {
            // handle error
            ...
        }    
        // Retrieve the Class of Device value of the 
        // remote device.
        device_class = 
                bt_rdev_get_device_class(next_remote_device, 
                                         BT_COD_DEVICECLASS);
        ...

        // Work with retrieved data as needed.
        ...

    }
    bt_rdev_free_array(remote_device_array);
}