Bluetooth Low energy gatt data sending too much information

521 Views Asked by At

I have an issue with my code being that I pass 51 bytes to a ble characteristic and, then call a function to send this to my phone via a pr established GATT connection however, it sends far more data then 51 bytes.

I have a function called ble_cus_send_csv it takes in several parameters. These are my custom structure, my data, the data length and the handler.

I send into it 51 chars which I believe is 51bytes. I take the sizeof() this and, it gives 51.

I then run my ble_cus_send_csv function and it runs and outputs my 51 bytes of data with far more bytes afterwards.

I have attached my send function below and my output. It should just output a fixed 51 bytes.

I am using a Nordic NRF52840-dk board inside segger studio. The code is written in C.

Thanks, Gatt characteristic data

My ble_cus_send_csv function:

uint32_t ble_cus_send_csv(ble_cus_t * p_cus,
                          uint8_t   * p_data,
                          uint16_t  * p_length,
                          uint16_t    conn_handle)
{
    ble_gatts_hvx_params_t hvx_params;
    NRF_LOG_INFO("Sending CSV.\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)) //Setup the parameters to pass into the characteristic value
    {

        memset(&hvx_params, 0, sizeof(hvx_params));

        hvx_params.handle = p_cus->custom_value_handles.value_handle;
        hvx_params.p_data = p_data;
        hvx_params.p_len  = p_length;
        hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;


        err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params);//Set the characteristic
        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;
}

P_length in the debugger

P_length

0

There are 0 best solutions below