When notification with big data, only maximum 4 notification is sent.

Dear Nordic support team,
I meet a situation: I have big data array need to transfer("arrayTransfer" with 3072 bytes)
to smart phone by notification method. Using timer 10s to send 3072 byte to smart phone.

I want to send 128 bytes data for one notification.

So I have to separate "arrayTransfer" to small array (128 bytes each notification).

It mean with 3072 byte we need send 24 notifies to smart phone.

I see that on our App only receive 4 notifies instead 24.

If I change separate "arrayTransfer" to small array (32 bytes each notification).

It mean with 3072 byte we need send 96 notifies to smart phone.

But we also only receive 4 notifies instead 96.

=> Why we only send maximum 4 time notification?

     I try with change number of notification byte: 128byte/32bytes/8bytes/... The same result, we on ly maximum 4 notifications is sent to smartphone.

=> How to change the maximum notification send? Can you see and help me review the "dataTransferHandler" function below.

thanks and best regards,

   



Here is my function code in the "main.c"

uint8_t arrayTransfer[3072]; 

void initArray(void)
{
 uint8_t i, j;
    for(i =0; i<24; i++)
    {
        for(j = 0; j< 128; j++)
        {
            arrayTransfer[i*loop2 + j] = j;
        }
    }
 
}
static void dataTransferHandler(void * p_context)
{

    UNUSED_PARAMETER(p_context);
    uint8_t dataTransfer[128];
    uint8_t dataLengthTransfer = sizeof(dataTransfer), i, j;
    ret_code_t err_code;
    

    for(i = 0; i< 24; i++)
    {
        for(j = 0; j<128; j++)
        {
            dataTransfer[j] = arrayTransfer[i*128+j+i];
        }
        err_code = ble_TWIs_temperature_update(&m_TWIs, dataTransfer, BLE_CONN_HANDLE_ALL, dataLengthTransfer);
    }


    if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE) &&
        (err_code != NRF_ERROR_RESOURCES) && (err_code != NRF_ERROR_BUSY) &&
        (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING))
    {
        APP_ERROR_HANDLER(err_code);
    }
}



int main(void)
{
    bool erase_bonds;
    ret_code_t err_code;
    // Initialize.
    log_init();
    timers_init();
    initArray();
    ......
}


Parents
  • Hi,

    How does the function ble_TWIs_temperature_update() look like?

    Can you print what the function is returning?

  • hello Sigurd,

    Bellow is the ble_TWIs_temperature_update()

    ret_code_t ble_TWIs_temperature_update(ble_TWIs_t * p_TWIs, uint8_t     *pData, uint16_t    conn_handle, uint16_t datalength)
    {
        if (p_TWIs == NULL)
        {
            return NRF_ERROR_NULL;
        }
    
        ret_code_t         err_code = NRF_SUCCESS;
        ble_gatts_value_t  gatts_value;
    
        //if (currentVal != lastVal)
        {
            // Initialize value struct.
            memset(&gatts_value, 0, sizeof(gatts_value));
    
            gatts_value.len     = datalength * sizeof(uint8_t);
            gatts_value.offset  = 0;
            gatts_value.p_value = pData;
    
            // Send value if connected and notifying.
            if (p_TWIs->is_notification_supported)
            {
                ble_gatts_hvx_params_t hvx_params;
    
                memset(&hvx_params, 0, sizeof(hvx_params));
    
                hvx_params.handle = p_TWIs->TWI2C_level_handles.value_handle;
                hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
                hvx_params.offset = gatts_value.offset;
                hvx_params.p_len  = &datalength;
                hvx_params.p_data = gatts_value.p_value;
    
                if (conn_handle == BLE_CONN_HANDLE_ALL)
                {
                    NRF_LOG_DEBUG("conn_handle == BLE_CONN_HANDLE_ALL")
                    ble_conn_state_conn_handle_list_t conn_handles = ble_conn_state_conn_handles();
                    // Try sending notifications to all valid connection handles.
                    for (uint32_t i = 0; i < conn_handles.len; i++)
                    {
                        if (ble_conn_state_status(conn_handles.conn_handles[i]) == BLE_CONN_STATUS_CONNECTED)
                        {
                            if (err_code == NRF_SUCCESS)
                            {
                                err_code = temperature_notification_send(&hvx_params,
                                                                     conn_handles.conn_handles[i]);
                                 NRF_LOG_DEBUG("Try sending notifications to all valid connection handles")
                            }
                            else
                            {
                                // Preserve the first non-zero error code
                                UNUSED_RETURN_VALUE(temperature_notification_send(&hvx_params, conn_handles.conn_handles[i]));
                            }
                        }
                    }
                }
                else
                {
                    NRF_LOG_DEBUG("conn_handle != BLE_CONN_HANDLE_ALL")
                    err_code = temperature_notification_send(&hvx_params, conn_handle);
                }
            }
            else
            {
                err_code = NRF_ERROR_INVALID_STATE;
            }
        }
        return err_code;
    }

  • yes, i tried but the same.

    Do i need change more parameter?

  • Try to set the hvn_tx_queue_size directly as well, and see if it improves anything, snippet:

    /**@brief Function for the SoftDevice initialization.
     *
     * @details This function initializes the SoftDevice and the BLE event interrupt.
     */
    static void ble_stack_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
    
        // Configure the BLE stack using the default settings.
        // Fetch the start address of the application RAM.
        uint32_t ram_start = 0;
        err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
        APP_ERROR_CHECK(err_code);
    
        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);
        if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_CONN_CFG_GATTS.",
                          nrf_strerror_get(err_code));
        }
    
    
    
        // Enable BLE stack.
        err_code = nrf_sdh_ble_enable(&ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Register a handler for BLE events.
        NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
    }

    And also try to enable Connection Event Length Extension, snippet:

        ret_code_t err_code;
        ble_opt_t  opt;
    
        memset(&opt, 0x00, sizeof(opt));
        opt.common_opt.conn_evt_ext.enable = 1;
    
        err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
        APP_ERROR_CHECK(err_code);

  • hi Sigurd,

    where to add this code below?

        ret_code_t err_code;
        ble_opt_t  opt;
    
        memset(&opt, 0x00, sizeof(opt));
        opt.common_opt.conn_evt_ext.enable = 1;
    
        err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
        APP_ERROR_CHECK(err_code);

  • Hi,

    Somewhere after you call ble_stack_init()

Reply Children
No Data
Related