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

Problem with sd_ble_gatts_hvx without notifications enabled

Hi there!

I am trying to add custom UUID's for my BLE application. I have a custom service which has 2 RX and 3 TX characteristics.

I have a situation where the Android APP that I am using doesn't notify. Because of this I am not able to write my data into one of the TX characteristics to transmit data to the mobile.

This results in sd_ble_gatts_hvx() returning error code as 8 - INVALID STATE.

As a workaround I added the following:

    case BLE_GAP_EVT_CONNECTED:
    	gu16_connhandle = lsp_ble_evt->evt.gap_evt.conn_handle;
    	errcode = sd_ble_gatts_sys_attr_set(gu16_connhandle, NULL, 0, 0);

As this did not work, I tried doing the following too:

    	lu16ar_Buffer[0] = 16;      // cccd handle
    	lu16ar_Buffer[1] = 2;       // cccd attribute size = 2
    	lu16ar_Buffer[2] = 1;       // 1 = enable notifications
    	lu16ar_Buffer[3] = 0xCACD;  // CRC-CCITT (0xFFFF)
    	lu32_errcode = sd_ble_gatts_sys_attr_set(gu16_connhandle, (u8*)lu16ar_Buffer, 8, 0);

Inspite of doing the above, I did not have any luck transmitting the BLE data that I intend to.

Is there any way that I can transmit (write in the characteristics) without the notification being enabled from the Android APP?

I am using SDK 12.1

Thanks in advance!

Parents Reply Children
  • Hi, Thanks for your reply! I did add the below piece of code in on_connect() with no luck:

    uint32_t          err_code;
    uint8_t           default_protocol_mode;
    ble_gatts_value_t gatts_value;
    
    lsp_nus->conn_handle = lsp_ble_evt->evt.gap_evt.conn_handle;
    
    if (lsp_nus->rx_handles.value_handle)
    {
        // Set Protocol Mode characteristic value to default value
        default_protocol_mode = 0;
    
        // Initialize value struct.
        memset(&gatts_value, 0, sizeof(gatts_value));
    
        gatts_value.len     = sizeof(uint8_t);
        gatts_value.offset  = 0;
        gatts_value.p_value = &default_protocol_mode;
    
        err_code = sd_ble_gatts_value_set(lsp_nus->conn_handle,
        		lsp_nus->rx_handles.value_handle, &gatts_value);
    

    The following link: devzone.nordicsemi.com/.../

    claims that sd_ble_gatts_value_set() might not serve the purpose. Any thing else that I can try to make this work?

  • That link only say that you cannot write the cccd of the characteristics using sd_ble_gatts_value_set(). You should still be able to set the value of the characteristics using this function. I tested this on the BLE UART example, and that works fine. Are you getting any error codes from sd_ble_gatts_value_set() when you use that code? Note that you explicitly have to read the characteristics on the phone to get the value, you will not get any hints that a new value is available.

  • Yes true, I used sd_ble_gatts_value_set() to set the value directly as you mentioned. I did not get any error code, meaning return from this function was 0. I did try to explicitly read from the phone to fetch the value, but this was not successful. However I used another method. I manually enabled notification by using the function sd_ble_gatts_sys_attr_set(). I calculated the CRC (CRC-CCIT - 0xFFFF) and updated the same using this function. With the updated system attributes, I used sd_ble_gatts_hvx() to write the values. This seems to be working fine. Of course I have to explicitly read the value from the mobile.

  • Hello. I'd like to read the temperature values in my nordic thingy without enabling notifications. Is there a way one can use the function sd_ble_gatts_value_set() to do this?

Related