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

Unexpected return value when calling sd_ble_gatts_hvx() when notifications are not enabled

This issue concerns code using Softdevice S132 v6.1.1. v5.0.0. I did not test with any other version.

From the documentation of sd_ble_gatts_hvx in ble_gatts.h, I expect that the return value when calling this function while notifications are disabled for the characteristic in question is NRF_ERROR_INVALID_STATE.

Instead, the function returns BLE_ERROR_NOT_ENABLED, which suggests that the softdevice is not enabled, but this is of course not the case because the device in question is connected when the issue arises.

Parents Reply Children
  • Hi.

    The error you see is not BLE_ERROR_NOT_ENABLED, but BLE_ERROR_GATTS_SYS_ATTR_MISSING.

    We can first take a look at the math for the two different definitions:

    NRF_ERROR_STK_BASE_NUM = 0x3000 in the SDK

    BLE_ERROR_NOT_ENABLED = NRF_ERROR_STK_BASE_NUM + 0x001 = 0x3001

    BLE_ERROR_GATTS_SYS_ATTR_MISSING = NRF_GATTS_ERR_BASE + 0x001 = NRF_ERROR_STK_BASE_NUM + 0x400 + 0x001 = 0x3401

    Also checked that this is the value by debugging:

    Can also see that sd_ble_enabled returns 0x8 which is invalid state (NRF_ERROR_INVALID_STATE):

    So I'm pretty confident that the error is BLE_ERROR_GATTS_SYS_ATTR_MISSING, and the solution to handle this error is described here.

    Best regards,

    Andreas

Related