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

How to access the Device Name Characteristic

I was trying around some experiments with the Sdk 5.1 Hrs Example code. I want to do something special (e.g. turn on a led on the nRF6100 board) when the devicename was changed by a ble central to a specific value.

For that, I think I have to hook into ble_evt_dispatch() and must check the parameter p_ble_evt against anything, right? E.g.

static void ble_evt_dispatch(ble_evt_t * p_ble_evt) {
    ble_bondmngr_on_ble_evt(p_ble_evt);
    ble_hrs_on_ble_evt(&m_hrs, p_ble_evt);
    ble_bas_on_ble_evt(&m_bas, p_ble_evt);
    ble_conn_params_on_ble_evt(p_ble_evt);
    on_ble_evt(p_ble_evt);
    { // Joe: My own experimental code starts here
        ble_gatts_evt_write_t* p_evt_write = 
                &p_ble_evt->evt.gatts_evt.params.write;
        // 3 = device name handle
        // TODO JM: is there a better way?
        if (p_evt_write->handle == 3) {
            // TODO: How to access the Device Name?
            if (strcmp("?!?", "LED") == 0) { 
                nrf_gpio_cfg_output(LED_4);
                nrf_gpio_pin_set(LED_4);
            }
        }
    }
}

Could someone tell me how I can retrive the device name?

Parents
  • Hi Joe,

    @TODO JM: is there a better way?

    The UUID of the Device name characteristic is 0x2A00. So you can do something like this..

    [i]if (p_ble_evt->evt.gatts_evt.params.write.context.char_uuid == BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME) [/i] instead of

    if (p_evt_write->handle == 3)

    The macro BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME is defined to 0x2A00 in ble_types.h.

    @How to access the Device Name

    You can retrieve the device name from the field p_ble_evt->evt.gatts_evt.params.write.data. The length of the device name will be in p_ble_evt->evt.gatts_evt.params.write.len.

    Hope this helps.

    Cheers, Balaji

Reply
  • Hi Joe,

    @TODO JM: is there a better way?

    The UUID of the Device name characteristic is 0x2A00. So you can do something like this..

    [i]if (p_ble_evt->evt.gatts_evt.params.write.context.char_uuid == BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME) [/i] instead of

    if (p_evt_write->handle == 3)

    The macro BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME is defined to 0x2A00 in ble_types.h.

    @How to access the Device Name

    You can retrieve the device name from the field p_ble_evt->evt.gatts_evt.params.write.data. The length of the device name will be in p_ble_evt->evt.gatts_evt.params.write.len.

    Hope this helps.

    Cheers, Balaji

Children
Related