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

BLE adding characteristic doesn´t work

Hi,

I´m trying to add a new, custom TX characteristic to Softdevice. I use example from SDK 16 "UART/Serial Port Emulation over BLE".

How I can do this, is explained here: "https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Fble_sdk_app_nus_eval.html&cp=7_1_4_2_2_25_0_0&anchor=adding_prop_ser_and_char"

So I add the following code to "ble_nus.c":

#define test                           0x0005               /**< The UUID of the test Characteristic. */
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = test;
add_char_params.uuid_type = p_nus->uuid_type;
add_char_params.max_len = BLE_NUS_MAX_TX_CHAR_LEN;
add_char_params.init_len = sizeof(uint8_t);
add_char_params.is_var_len = true;
add_char_params.char_props.notify = 1;

add_char_params.read_access = SEC_OPEN;
add_char_params.write_access = SEC_OPEN;
add_char_params.cccd_write_access = SEC_OPEN;

return characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->tx_handles);

But there is no new TX characteristic in nRF connect App. The both other standard characteristics are addet in similar way.

What I´m doing wrong?

Parents Reply
  • Oh, this was my fault. I corrrected it in my first post. The variable "test" (0x0005) is used for "add_char_params.uuid". But it doesn´t work though.

    I turned Bluetooth on and off. It doesn´t help. I changed UUID value for the standard characteristics and build the project again. nRF Connect shows the new UUID´s, so I think thewre is no problem with chache.

    Can I do something other?

Children
  • I don´t know why, but if I comment out 

    return characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->tx_handles);

    and add

    err_code = characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->tx_handles);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }

    it work´s  :-)

    I can now add characteristics as required. Thank you for your help.

    I have a second question, maybe you can help me:

    The data, which is sent by BLE to nRF connect is handled in the function "uart_event_handle()". Now, I have added four characteristics. The data, recieved from UART, always transmitt to the fourth characteristic.

    Where can I see to which characteristic the data is send to? The function "ble_nus_data_send" gives no information about that? Where can I control this?

    Thanks in advace!

    Simon

  • Hello Simon.

    So you say that all the data that you send is sent via the last characteristic?

    If you look at the implementation of ble_nus_data_send(), you will see that it uses a handle called:

    hvx_params.handle = p_nus->tx_handles.value_handle;

    So if this handle is used in the implementation of the characteristic, I guess it would always be the last one.

    You should add a new handle to all the new characteristics that you add. Look at how the tx_handle is added, compared to the rx_handle in the unmodified example.

    Try adding some new handles in:

    struct ble_nus_s
    {
        uint8_t                         uuid_type;          /**< UUID type for Nordic UART Service Base UUID. */
        uint16_t                        service_handle;     /**< Handle of Nordic UART Service (as provided by the SoftDevice). */
        ble_gatts_char_handles_t        tx_handles;         /**< Handles related to the TX characteristic (as provided by the SoftDevice). */
        ble_gatts_char_handles_t        rx_handles;         /**< Handles related to the RX characteristic (as provided by the SoftDevice). */
        blcm_link_ctx_storage_t * const p_link_ctx_storage; /**< Pointer to link context storage with handles of all current connections and its context. */
        ble_nus_data_handler_t          data_handler;       /**< Event handler to be called for handling received data. */
    };

    in ble_nus.h, and use these handles instead of the tx_handle when you add the new characteristics.

    Then you need to add something in ble_nus_data_send() that can take one extra parameter, which says what characteristic handle that you want to use to send the data.

Related