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

BLE lost messages

Hi, as part of my project i have 2 nordic 52dks one as a pheripheral (sending) and on as a client (recieving). where i am sening a buffer of 8, in the order

buffer[0] = 10

buffer[1}= X gyro lsb

buffer[2] = X gyro msb

buffer[3] = y gyro lsb

buffer[4] = y gyro msb

buffer[5] = z gyro lsb

buffer[6] = z gyro msb

buffer[7] = 36   //terminator $

however sometimes i seem to lose a byte over ble such that the next byte received will be less and hence the order is correupted thus making processing rather and unpredictable for a large sample size like 1000000 samples.

how may i ensure that my ble settings are correct such that i ensure to limit this issue.

my code was based of the examples ble_app_uart and ble_app_uart_c for the peripheral and client respectivly.

thank u in advance 

  • Yes, and which function return the error code that fails this APP_ERROR_CHECK?

    uint32_t err_code2 =ble_nus_data_send(&m_nus,send_buffer3, &length3, m_conn_handle);  line 910
    APP_ERROR_CHECK(err_code2); line 911

    Is the client encountering any errors? Are you saying that the code we are looking at right now is for the peripheral - but that the resetting happens on the central, and not on the peripheral?

    yes exactly that , the central doesnt seem to return error codes but when it resets it gets stuck in a nrf_breakpoint_condition 

    Calling ble_nus_data_send queues data for sending as a notification during the next connection event. However, if you try to queue too many notifications too fast, the ble_nus_data_send function will return NRF_ERROR_RESOURCES, indicating that its buffer is full, and that the call to queue data failed.
    You may then use the BLE_GATTS_EVT_HVN_TX_COMPLETE event to know when a notification successfully has been sent - meaning that you may now queue another notification for transfer, because it is now room in the buffer.

    can you maybe show me how i can do this , such that i can do a while loop to wait for the tx buffer to be sent to ensure i dont queue too many notifications. can you show me how i need to use it and wherre i need to place this event please.

    you think this could work?

  • NikTheNordicUser said:
    uint32_t err_code2 =ble_nus_data_send(&m_nus,send_buffer3, &length3, m_conn_handle);  line 910
    APP_ERROR_CHECK(err_code2); line 911

    Thanks. So, now we know both which function that returned the error, and which error it returned.
    Looking into the source code of ble_nus_data_send, we see that it forwards error codes from sd_ble_gatts_hvx. Then we check why the sd_ble_gatts_hvx would return the NRF_ERROR_RESOURCES error, the exempt from the API Reference reads:

    NRF_ERROR_RESOURCES Too many notifications queued. Wait for a BLE_GATTS_EVT_HVN_TX_COMPLETE event and retry.

    So we know that we need to wait for an BLE_GATTS_EVT_HVN_TX_COMPLETE event before we queue more data for transfer. We also read from the note section that the hvx_queue size can be changed to accommodate for more samples queued for transfer before the NRF_ERROR_RESOURCES is generated.
    What is your current size of BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT?
    If you know how many notifications will be queued between each connection event, you could set this buffer to at least be able to hold this number of notifications (plus a couple more for good measure in case of re-transmissions).

    NikTheNordicUser said:
    can you show me how i need to use it and wherre i need to place this event please.

    The ble_evt_handler is passed all the SoftDevice events. You could implement the logic for the BLE_GATTS_EVT_HVN_TX_COMPLETE here.

    Best regards,
    Karl

  • What is your current size of BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT?

    i found that in the ble_gatts.h (of the pheripheral code) it is set as 1

    You could implement the logic for the BLE_GATTS_EVT_HVN_TX_COMPLETE here.

    is it possible to maybe show me how ? please

  • NikTheNordicUser said:
    i found that in the ble_gatts.h (of the pheripheral code) it is set as 1

    So there is only space to queue 1 notification for transfer before you will generate the NRF_ERROR_RESOURCES.
    How many notifications do you intend to queue between each connection event?

    NikTheNordicUser said:
    is it possible to maybe show me how ? please
    Karl Ylvisaker said:
    The ble_evt_handler is passed all the SoftDevice events. You could implement the logic for the BLE_GATTS_EVT_HVN_TX_COMPLETE here.

    Add a case for this event into the ble_evt_handler, then implement the logic you would like to have happen when this event is generated. What do you intend to have happen when this event is generated?

    Best regards,
    Karl

  • How many notifications do you intend to queue between each connection event?

    umm.. im not really sure is there a max value ? My application requires for fast transfer as i mentioned in the very begining the pheripheral board contains a gyro and acc sensor which communicates via spi and this pheripheral board sits on a motor such that i measure RPM in matlab after the hex data of sensor is sent via ble to the client pcb. is there a max number of queue as ideally meanwhile i am filling up the sending buffer with the spi data i would be sending a previously filled buffer. thats why i would like to monitor the ble gatts event tx complete flag such that i can remove all delays and ensure that data is fully sent and there are no queuse before i send another buffer

    im not sure if wat im saying is understandable.

Related