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?

  • Hi Juliane,

    Once the IOS app writes to the Device Name characteristic, you will have to store it in flash at a predefined location. Each time the app starts up (from System Off mode), it should read that location and advertise with that device name. You can use the pstorage module included in the SDK to do the flash operation.

    Does it answer your question?

    Cheers, Balaji

  • Hi Balaji,

    It is the best way to solve my problem,but I don't know how can I achieve that,is there any example for my problem?

    Thanks! Juliane

  • Hi Julian,

    As Balaji recommends using PStorage module in SDK can help you store the device name persistently.

    PStorage module is currently used to store bonding information in persistent memory (flash on nrf51 devices). What you can do to be able to store your data is register with the module using the pstorage_register API. Note that in pstorage_platform.h for your example, increase the number of applications by 1 in order that the API succeeds. You can request 1 block of maximum_size you wish to permit for your device name. Please note that BLE_GAP_DEVNAME_MAX_LEN limits the device name to be set locally, hence this may be a consideration to chose the maximum limit.

    On success of this API, you will get a reference 'handle' to the persistent memory where you can store device name. Using this handle you can store and load data when you like using pstorage_store and pstorage_load functions respectively. I recommend you read PStorage documentation before getting started.

    Things to consider: a. You may want to store the length of local device name along with the name instead of relying in null terminated strings to be to support variable length device name with errors. b. When registering with the PStorage module, remember that you request only multiples of 4, therefore, if you wish to maximum limit the device name to 31, you will have to request a block of size 32. c. One entire flash page of size 1024 will be reserved even if you request 1 block of size 32.

    Hope this helps!

    Regards, Krishna

Related