Look up remote device information

The Bluetooth APIs provide functions to query various aspects of a remote device such as basic device information, services, and low energy parameters, if applicable.

The following code snippet demonstrates how to retrieve remote device information using some of these functions. For information on how to discover devices, see Search for remote devices.
#define UNKNOWN "Unknown"

char name[128] = UNKNOWN;
char addr[128];
int device_class = -1;
int device_type = -1;
bool encrypted = false;
bool paired = false;

// Search for remote devices.
...

// Retrieve the remote device we are interested in.
bt_remote_device_t *remote_device = bt_rdev_get_device(device_address);
if (!remote_device) {
    return;
}

char buffer[128];
const int bufferSize = sizeof(buffer);

// Retrieve basic device information.
// 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(remote_device, buffer, bufferSize) 
        == 0) {
    strcpy(name, buffer);
}

strcpy(addr, deviceAddress);

// Retrieve the Class of Device value.
device_class = bt_rdev_get_device_class(remote_device, 
                                        BT_COD_DEVICECLASS);

// Retrieve the remote device type.
device_type = bt_rdev_get_type(remote_device);

// Determine if the connection with the remote device is encrypted.
if ((bt_rdev_is_encrypted(remote_device)) {
    encrypted = true;
}

// Determine if the device is paired.
if (bt_rdev_is_paired(remote_device, &paired) != 0) {
    // Handle error
    ...
}    
...
   
// Retrieve services
char **services_array = bt_rdev_get_services(remote_device);
if (services_array != NULL) {
    // Work with retrieved services
    ...
 
    // Free the resources used for the services array.
    bt_rdev_free_services(services_array);
}

// If the remote device is a low-energy device, 
// retrieve low-energy services.
if (deviceType == BT_DEVICE_TYPE_LE_PUBLIC || 
    deviceType == BT_DEVICE_TYPE_LE_PRIVATE) {
    
    services_array = bt_rdev_get_services_gatt(remote_device);
    if (services_array != NULL) {
        // Work with retrieved services
        ...
     
        // Free the resources used for the services array.
        bt_rdev_free_services(services_array);
    }
}

// Free resources.
bt_rdev_free(remote_device);