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
  • Manually enable notification and calculate the CRC (CRC-CCIT - 0xFFFF). Update the new attributes along with CRC using the function sd_ble_gatts_sys_attr_set(). With the updated system attributes, use sd_ble_gatts_hvx() to write the values. This seems to be working fine. Of course we have to explicitly read the value from the mobile. Each CCCD is 3 byte long (SDK12.1). This is followed by 2 byte CRC at the end. So if the CCCD count is 3, length would be: 3x6 + 2 = 14

Reply
  • Manually enable notification and calculate the CRC (CRC-CCIT - 0xFFFF). Update the new attributes along with CRC using the function sd_ble_gatts_sys_attr_set(). With the updated system attributes, use sd_ble_gatts_hvx() to write the values. This seems to be working fine. Of course we have to explicitly read the value from the mobile. Each CCCD is 3 byte long (SDK12.1). This is followed by 2 byte CRC at the end. So if the CCCD count is 3, length would be: 3x6 + 2 = 14

Children
Related