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

sd_ble_gatts_hvx returns unexpected value when indication not enabled

The API for sd_ble_gatts_hvx says that NRF_ERROR_INVALID_STATE is returned when no indications are enabled.

 * @retval ::NRF_ERROR_INVALID_STATE One or more of the following is true:
 *                                   - Invalid Connection State
 *                                   - Notifications and/or indications not enabled in the CCCD
 *                                   - An ATT_MTU exchange is ongoing

However, when I call sd_ble_gatts_hvx in this scenario I receive BLE_ERROR_GATTS_SYS_ATTR_MISSING

Is this a bug or inaccurate documentation? Something else?

Parents Reply
  • Hi, 

    There is a BLE_GATTS_EVT_SYS_ATTR_MISSING event that is generated when you try to read the CCCD and this event is usually handled inside the Peer Manager. So when you do not initialize the Peer Manager, then this event will not be handled correctly. If you do not use the Peer Manager in your code, then you can simply add the following snippet to on_ble_evt() in main.c. You also can take a look at the main.c in the ble_app_blinky example of how to handle that. 

            case BLE_GATTS_EVT_SYS_ATTR_MISSING:
                // No system attributes have been stored.
                err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
                APP_ERROR_CHECK(err_code);
                break;
    

    -Amanda H.

Children
Related