BLE questions characteristics

Hi,

I'm using nrf52840 and connect to a PC with BLE, using Nordic Uart Service (Rx and Tx characteristics).

When sending messages, I need to know how much data I'm writing to the characteristics and how fast. Can you please tell me how can I know that?

In addition - how can I know if I am using Notifications and Indications?

Thanks!

Parents
  • Hi 

    When sending messages, I need to know how much data I'm writing to the characteristics and how fast. Can you please tell me how can I know that?

    I assume you mean you want to know how much data you are writing over time?

    One way to do this is to just update a counter value each time you call the ble_nus_data_send(..) function, and then read and clear the counter value at a fixed rate (using an app_timer callback for instance). 

    If you check the counter value every second you can directly convert it to a KB/s reading. 

    In addition - how can I know if I am using Notifications and Indications?

    The NUS service supports Notifications only, and will never use Indications. 

    If you check the implementation of the ble_nus_data_send() function in ble_nus.c you can see how this is configured when sending data: 

    memset(&hvx_params, 0, sizeof(hvx_params));
    
    hvx_params.handle = p_nus->tx_handles.value_handle;
    hvx_params.p_data = p_data;
    hvx_params.p_len  = p_length;
    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
    
    return sd_ble_gatts_hvx(conn_handle, &hvx_params);

    The reason Indications is not supported is that the NUS TX characteristic is configured with the notify property only, as shown in the ble_nus_init() function in ble_nus.c:

    // Add the TX Characteristic.
    /**@snippet [Adding proprietary characteristic to the SoftDevice] */
    memset(&add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid              = BLE_UUID_NUS_TX_CHARACTERISTIC;
    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);
    /**@snippet [Adding proprietary characteristic to the SoftDevice] */

    Best regards
    Torbjørn

Reply
  • Hi 

    When sending messages, I need to know how much data I'm writing to the characteristics and how fast. Can you please tell me how can I know that?

    I assume you mean you want to know how much data you are writing over time?

    One way to do this is to just update a counter value each time you call the ble_nus_data_send(..) function, and then read and clear the counter value at a fixed rate (using an app_timer callback for instance). 

    If you check the counter value every second you can directly convert it to a KB/s reading. 

    In addition - how can I know if I am using Notifications and Indications?

    The NUS service supports Notifications only, and will never use Indications. 

    If you check the implementation of the ble_nus_data_send() function in ble_nus.c you can see how this is configured when sending data: 

    memset(&hvx_params, 0, sizeof(hvx_params));
    
    hvx_params.handle = p_nus->tx_handles.value_handle;
    hvx_params.p_data = p_data;
    hvx_params.p_len  = p_length;
    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
    
    return sd_ble_gatts_hvx(conn_handle, &hvx_params);

    The reason Indications is not supported is that the NUS TX characteristic is configured with the notify property only, as shown in the ble_nus_init() function in ble_nus.c:

    // Add the TX Characteristic.
    /**@snippet [Adding proprietary characteristic to the SoftDevice] */
    memset(&add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid              = BLE_UUID_NUS_TX_CHARACTERISTIC;
    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);
    /**@snippet [Adding proprietary characteristic to the SoftDevice] */

    Best regards
    Torbjørn

Children
  • Thanks you very much!

    I have another question regarding ble_gatt_char_props_t.

    I can see that Tx characteristic defines notification only, but Rx defines write and write_wo_resp. Does it mean that the other sides has the permissions to write to the Rx, so I will be able to read the bytes?

    Thanks!

  • Hi 

    Notifications are used by the server to send data instantly to the client, while write and write_wo_resp is used by the client to send data to the server. 

    The difference between write and write_wo_resp is that the first is a request, while the second is a command. Requests need to be replied to from the application, which makes them slower, so normally write_wo_resp is used. 

    The terms "TX" and "RX" characteristic are a bit misleading, but makes sense if you look at it from the server (peripheral) side. 
    When the server sends notifications to the client it is using the TX characteristic, while data coming from the client to the server is handled by the RX characteristic. 

    Best regards
    Torbjørn

Related