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

Ble Data Transfer Integrity

I am trying to send data from a phone to the NRF51822. The data is being sent from the phone in 20 byte chunks to a write characteristic. When the event handler for receiving data is called, I use sd_ble_gatts_value_get() to get the data and copy it to a buffer. The problem I see is that part of the previous packet is returned instead of the current one, but it does have the right length. For example, if I sent 5 20-byte packets numbered 0 - 99, the first 60 would have the right number, but byte 61 might have the number 56 instead of 60. Are there any methods to improve data integrity over BLE?

Thanks!

Parents
  • All data transferred over BLE is reliable, so I suspect you have some issues other place, for instance in the application handling in the central or peripheral. To check where the problem may be you might need to create a sniffer log and send to me when the problem occurs.

    https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Sniffer 

  • I have run the sniffer with my application, and I can tell that the correct data is being sent to the NRF51822. Here is the sniffer output if you are curious. The following code is called when BLE_GATTS_EVT_WRITE event occurs. 

    #define MAX_PACKET_SIZE 20
    static uint8_t data_buffer[MAX_PACKET_SIZE];
    void onCharWrite(ble_evt_t * p_ble_evt)
    {
        // Populate ble_gatts_value_t structure to hold received data and metadata.
        ble_gatts_value_t rx_data;
        rx_data.len = MAX_PACKET_SIZE;
        rx_data.offset = 0;
        rx_data.p_value = data_buffer;
        ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
        uint32_t error = NRF_SUCCESS;
        const uint16_t WriteHandle = p_evt_write->handle;
    
        if (WriteHandle == CharWriteHandles.value_handle)
        {
            // Get data
            memset(data_buffer, 0, MAX_PACKET_SIZE);
            error = sd_ble_gatts_value_get(zwConnection, CharWriteHandles.value_handle, &rx_data);
            APP_ERROR_CHECK(error);
            
            print_hex_buffer(&data_buffer[rx_data.offset], rx_data.len);
            
            //Copying to buffers and other processing
        }
    }

    Is there something wrong with the way this is being handled?

Reply
  • I have run the sniffer with my application, and I can tell that the correct data is being sent to the NRF51822. Here is the sniffer output if you are curious. The following code is called when BLE_GATTS_EVT_WRITE event occurs. 

    #define MAX_PACKET_SIZE 20
    static uint8_t data_buffer[MAX_PACKET_SIZE];
    void onCharWrite(ble_evt_t * p_ble_evt)
    {
        // Populate ble_gatts_value_t structure to hold received data and metadata.
        ble_gatts_value_t rx_data;
        rx_data.len = MAX_PACKET_SIZE;
        rx_data.offset = 0;
        rx_data.p_value = data_buffer;
        ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
        uint32_t error = NRF_SUCCESS;
        const uint16_t WriteHandle = p_evt_write->handle;
    
        if (WriteHandle == CharWriteHandles.value_handle)
        {
            // Get data
            memset(data_buffer, 0, MAX_PACKET_SIZE);
            error = sd_ble_gatts_value_get(zwConnection, CharWriteHandles.value_handle, &rx_data);
            APP_ERROR_CHECK(error);
            
            print_hex_buffer(&data_buffer[rx_data.offset], rx_data.len);
            
            //Copying to buffers and other processing
        }
    }

    Is there something wrong with the way this is being handled?

Children
Related