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

Getting error NRF_ERROR_RESOURCES when using more then one notification and the Connection crashes

Hi, 

I am using the MCU on a board with sensors that are sampled in a very high rate (~100Hz). 

I am having issues when trying to send the data with notification on more then one characteristic. 

The information is sent correctly for a short time (~30 seconds) and then the connection get stuck and unresponsive. 

When the connection "crashes" i start getting NRF_ERROR_RESOURCES  from sd_ble_gatts_hvx(*pointer_conn_handle, &hvx_params);

Initially i thought it is because the queue was very small (the default value of 1) however even after changing it to 10 it still does it.

I use the following code to change it: 

ble_cfg_t ble_cfg;
memset(&ble_cfg, 0, sizeof ble_cfg);
ble_cfg.conn_cfg.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;
ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 10;
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, ram_start);

I have 2 questions:

1. how can i config the system to allow much more bandwidth as i will need several notification simultaneously?

2. how can i avoid crashes in case of overload? i saw this post but couldn't understand how to use it on my project as the data structs are different.

I am using NRF52832 (custom board) with freeRTOS (based on the HRS freeRTOS example) SDK15, and SD 6.0

BR, 

Danny

Parents
  • Hi,

    1. how can i config the system to allow much more bandwidth as i will need several notification simultaneously?

    Please try to increase the event length(NRF_SDH_BLE_GAP_EVENT_LENGTH). See this post.

    2. how can i avoid crashes in case of overload? i saw this post but couldn't understand how to use it on my project as the data structs are different.

    The quick and easy solution is just to wait for the function to return something else than NRF_ERROR_RESOURCES.

    err_code = your_send_function / sd_ble_gatts_hvx
    
    if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_RESOURCES) &&
    	 (err_code != NRF_ERROR_NOT_FOUND) )
    {
    	APP_ERROR_CHECK(err_code);
    }
    } while (err_code == NRF_ERROR_RESOURCES);

    You could also set a flag when you get NRF_ERROR_RESOURCES, and wait for the BLE_GATTS_EVT_HVN_TX_COMPLETE event to occur, and try again. This is done in the ble_app_att_mtu_throughput example. But try to increase the event_length and do the easy solution first.

    Let me know how it goes.

    BR,

    Sigurd

  • Hi Sigurd,

    I have increased the NRF_SDH_BLE_GAP_EVENT_LENGTH from 6 to 100 but still no luck i still get NRF_ERROR_RESOURCES after several seconds. 

    In addition i tried to add the while loop in order to retry the sd_ble_gatts_hvx it get stuck in the loop and never recover. 

    It feels like the resource shortage cause the soft device to stop responding. in addition, i don't know if it is related, but when i connect to the device the sd_ble_gatts_hvx function returns 13313 which i couldn't find the meaning of..

    i am sending 200 packets per second which shouldn't be a too large amount. 

  • but when i connect to the device the sd_ble_gatts_hvx function returns 13313 which i couldn't find the meaning of..

    13313 is 0x3401 in hex, and is known as the error code BLE_ERROR_GATTS_SYS_ATTR_MISSING.

    As mentioned in this post, it probably occurs because you are trying to send a notification/indication to the client before the client has enabled the CCCD.

    See this post for more information. This and this post might also be helpful.

  • Hi, 

    I am not very concerned with the BLE_ERROR_GATTS_SYS_ATTR_MISSING

    The more concerning issue is the fact the connection crashes. basically the soft device stop responding and connection events aren't being handled.

    I have tried what you suggested but got nothing.

    the part of the notifications in my code is:

    if(*pointer_conn_handle != BLE_CONN_HANDLE_INVALID)
    {
        sd_ble_gatts_value_get(*pointer_conn_handle, Sensor_val_handles.cccd_handle, &cccd_data);
        if(*cccd_data.p_value)
        {
            ble_gatts_hvx_params_t hvx_params;
            memset(&hvx_params, 0, sizeof(hvx_params));
            rslt = 0;
            hvx_params.handle = Sensor_val_handles.value_handle;
            hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
            hvx_params.offset = 0;
            hvx_params.p_len = &value.len;
            hvx_params.p_data = (uint8_t*)data;
            rslt = sd_ble_gatts_hvx(*pointer_conn_handle, &hvx_params);
            if (rslt != 0)
        {
    }

    When i am getting NRF_ERROR_RESOURCES the soft device get "stuck" and it does not respond anymore. 

    this is a major issue and i must solve it. please let me know what else is required in order to solve this. 

    thank you, 

Reply
  • Hi, 

    I am not very concerned with the BLE_ERROR_GATTS_SYS_ATTR_MISSING

    The more concerning issue is the fact the connection crashes. basically the soft device stop responding and connection events aren't being handled.

    I have tried what you suggested but got nothing.

    the part of the notifications in my code is:

    if(*pointer_conn_handle != BLE_CONN_HANDLE_INVALID)
    {
        sd_ble_gatts_value_get(*pointer_conn_handle, Sensor_val_handles.cccd_handle, &cccd_data);
        if(*cccd_data.p_value)
        {
            ble_gatts_hvx_params_t hvx_params;
            memset(&hvx_params, 0, sizeof(hvx_params));
            rslt = 0;
            hvx_params.handle = Sensor_val_handles.value_handle;
            hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
            hvx_params.offset = 0;
            hvx_params.p_len = &value.len;
            hvx_params.p_data = (uint8_t*)data;
            rslt = sd_ble_gatts_hvx(*pointer_conn_handle, &hvx_params);
            if (rslt != 0)
        {
    }

    When i am getting NRF_ERROR_RESOURCES the soft device get "stuck" and it does not respond anymore. 

    this is a major issue and i must solve it. please let me know what else is required in order to solve this. 

    thank you, 

Children
Related