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

Data loss while sending large data by notifications with custom BLE service

Hello everyone,

A nRF52832 with SDK 15.0 was used for my application. I am trying to send a large amount of data via BLE with a custom BLE service. I extended MTU size so that it can meet my demand in both Client and Server. My Android app was developed to get the data. To check whether data sent by BLE device are lost or not, I added an index after a data package of 48-byte long. The following image is about index I got. 

There are 1, 2 or even 3 packages lost during data transmission. In this case, I tried to set the value of interval connection as low as possible (9ms). If I increased this interval as I have tested (24ms), there are more data packages lost.

Interestingly, if I use NUS BLE service instead and UART Android app to collect data,  this issue didn't happen and I can send up to 60 byte data per package without data loss. I double-checked my update data in custom BLE service, it is similar to that in NUS BLE service. 

Thus, are there any suggestion for me to solve this issue on the custom BLE service?

Thanks!

Parents
  • Hi,

    NUS BLE service instead and UART Android app to collect data,  this issue didn't happen

    Sounds like a bug in the Android-nRF-UART app then. It's deprecated, and it's almost 4 years since it was updated. I would recommend that you instead take a look at these repos, Android-BLE-Library , Android-Scanner-Compat-Library and Android-nRF-Toolbox

  • Hi Sigurd,

    What I meant is if I use NUS BLE service and Android nrF UART app for receiving large amount of data. It works well, there is no data loss at all.

    When I try to use custom BLE service and another Android app which I developed based on Android-nRF-Blinky, the data loss happens like 2 or 3 packages of 49-byte data long/package are missing. I tried to shorten interval connection as low as possible, but the issue wasn't solved yet.

    The following code is for my updating data function.

    uint32_t ble_cus_custom_value_update(ble_cus_t * p_cus, uint8_t* custom_value, uint16_t length)
    {
        NRF_LOG_INFO("In ble_cus_custom_value_update. \r\n"); 
        if (p_cus == NULL)
        {
            return NRF_ERROR_NULL;
        }
    
        uint32_t err_code = NRF_SUCCESS;
         // Send value if connected and notifying.
        if ((p_cus->conn_handle != BLE_CONN_HANDLE_INVALID)) 
        {
            ble_gatts_hvx_params_t hvx_params;
    
            memset(&hvx_params, 0, sizeof(hvx_params));
    
            hvx_params.handle = p_cus->custom_value_handles.value_handle;
            hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
            hvx_params.offset = 0; // only used if it is larger than 20 bytes
            hvx_params.p_len  = &length;
            hvx_params.p_data = custom_value;
    
            err_code = sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params); // Notify server
            NRF_LOG_INFO("sd_ble_gatts_hvx result: %x. \r\n", err_code); 
        }
        else
        {
            err_code = NRF_ERROR_INVALID_STATE;
            NRF_LOG_INFO("sd_ble_gatts_hvx result: NRF_ERROR_INVALID_STATE. \r\n"); 
        }
    
    
        return err_code;
    }

Reply
  • Hi Sigurd,

    What I meant is if I use NUS BLE service and Android nrF UART app for receiving large amount of data. It works well, there is no data loss at all.

    When I try to use custom BLE service and another Android app which I developed based on Android-nRF-Blinky, the data loss happens like 2 or 3 packages of 49-byte data long/package are missing. I tried to shorten interval connection as low as possible, but the issue wasn't solved yet.

    The following code is for my updating data function.

    uint32_t ble_cus_custom_value_update(ble_cus_t * p_cus, uint8_t* custom_value, uint16_t length)
    {
        NRF_LOG_INFO("In ble_cus_custom_value_update. \r\n"); 
        if (p_cus == NULL)
        {
            return NRF_ERROR_NULL;
        }
    
        uint32_t err_code = NRF_SUCCESS;
         // Send value if connected and notifying.
        if ((p_cus->conn_handle != BLE_CONN_HANDLE_INVALID)) 
        {
            ble_gatts_hvx_params_t hvx_params;
    
            memset(&hvx_params, 0, sizeof(hvx_params));
    
            hvx_params.handle = p_cus->custom_value_handles.value_handle;
            hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
            hvx_params.offset = 0; // only used if it is larger than 20 bytes
            hvx_params.p_len  = &length;
            hvx_params.p_data = custom_value;
    
            err_code = sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params); // Notify server
            NRF_LOG_INFO("sd_ble_gatts_hvx result: %x. \r\n", err_code); 
        }
        else
        {
            err_code = NRF_ERROR_INVALID_STATE;
            NRF_LOG_INFO("sd_ble_gatts_hvx result: NRF_ERROR_INVALID_STATE. \r\n"); 
        }
    
    
        return err_code;
    }

Children
No Data
Related