Ble slave to get master's device name #ble #nrf52480

Andrew Gu

Hi, I am making a program in a slave (peripheral) device. I can get a master (central) device connect to the slave (peripheral) device. But, how can I make the slave device to get the device name of the master device after the connection is on? I tried to use bt_gatt_read, but did not have any luck. My code is below. Can anyone help? Thanks in advance.

struct bt_conn *default_conn = NULL;
struct bt_gatt_read_params conn_param;
char devname[64];

u8_t conn_param_read_cb(struct bt_conn *conn, u8_t err, struct bt_gatt_read_params *params, const void *data, u16_t length) {
    if (err) return 0;
    memset(devname, 0, 64);
    memcpy(devname, data, length);
    return 0;

void connected(struct bt_conn *conn, u8_t err) {
    if (err) return;
    default_conn = bt_conn_ref(conn);
    conn_param.func = conn_param_read_cb;
    conn_param.handle_count = 1;
    conn_param.single.handle = sys_le16_to_cpu(0x2a00); //BT_UUID_GAP_DEVICE_NAME
    conn_param.single.offset = 0;
    bt_gatt_read(conn, &conn_param);