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

NUS example, authorize request, sd_ble_gatts_hvx

Hi together,

I'm using the NUS example (NRF52832) for client and peripheral, which is running quite well. My goal is to inform the peripheral application when notification was enabled on central side. Thus I added the line cccd_md.wr_auth = 1; in the function rx_char_add and added

switch (p_ble_evt->header.evt_id)
{
    case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
        {
            /* we get this event on peripheral side, when central enabled notifications */
            if(p_ble_evt->evt.gatts_evt.params.authorize_request.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
            {
                /* reply with SUCCESS/ALLOWED */
                ble_gatts_rw_authorize_reply_params_t rw_authorize_reply_params;
                memset(&rw_authorize_reply_params, 0, sizeof(rw_authorize_reply_params));
                rw_authorize_reply_params.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
                rw_authorize_reply_params.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;
                rw_authorize_reply_params.params.write.update = 1;
                err_code = sd_ble_gatts_rw_authorize_reply(m_ble_nus.conn_handle, &rw_authorize_reply_params);
                APP_ERROR_CHECK(err_code);

in the function on_ble_evt. With this, as soon the the function ble_nus_c_rx_notif_enable was called from central, the peripheral got a BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST such that I was able to inform the application that the central has enabled notifications. The described code was running very well with softdevice S132 1.0.0-3-alpha and sdk 0.9.2.

Now I'm using S132 V2.0.0 and nRF5 SDK 11.0.0 and get the following error: After connection setup, when I want to send data to the central using ble_nus_string_send the function sd_ble_gatts_hvx returns 0x3401. This was not the case, when using the "old" softdevice. How can I solve this problem?

Is there another way to inform the peripheral when a central connected and discovered all services successfully?

Thank you!

Parents
  • Hi Hauser,

    You received 0x3401 = BLE_ERROR_GATTS_SYS_ATTR_MISSING because you haven't called sd_ble_gatts_sys_attr_set() to init the system attribute. Have you made sure you called that in BLE_GATTS_EVT_SYS_ATTR_MISSING even in on_ble_evt() ?

    Also I don't really understand why do you need write with authorize request for this case. You can simply leave it as normal write, and catch the BLE_GATTS_EVT_WRITE even, and check for the handle ID of the CCCD characteristic. No need for authorized write here.

Reply
  • Hi Hauser,

    You received 0x3401 = BLE_ERROR_GATTS_SYS_ATTR_MISSING because you haven't called sd_ble_gatts_sys_attr_set() to init the system attribute. Have you made sure you called that in BLE_GATTS_EVT_SYS_ATTR_MISSING even in on_ble_evt() ?

    Also I don't really understand why do you need write with authorize request for this case. You can simply leave it as normal write, and catch the BLE_GATTS_EVT_WRITE even, and check for the handle ID of the CCCD characteristic. No need for authorized write here.

Children
Related