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

Connection timeout at central

Hi,

I'm using the example "ble_central/ble_app_uart_c" of nRF5_SDK_17.0.2. Connection to peripheral workes fine.

If the central re-starts while a connection is established, the peripheral get a "disconnect" event and wait for a new connection.

If the peripheral re-starts while a connection is established, the central get no "disconnect" event and runs into fatal error.

So, how to set up central, to handle a "disconnect" by timeout?

Thanks for helping!

  • Good Morning Karl,

    What connection interval are you using currently?

    If I'm right, the connection intervall is defined in sdk_config.h with 7.5...30 ms. So we can decrease the disconnection timeout, as you suggested.

    #define NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL   7.5
    #define NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL    30
    #define NRF_BLE_SCAN_SUPERVISION_TIMEOUT      4000

    The size of the queue, are you here talking about the UARTE RX buffer, or the hvn_tx_queue_size?

    In main.c the uart buffer size is defined by 256 Byte. Increasing or decreasing this size has no effect to the disconnection detection. If the connection is broken, it takes around 4 seconds and the central runs into the error handle, before to detect disconnection.

    Is it a possibility for you to use flow control?

    Using flow control is not desired. Is there a way to disable / enable uart interrupts by application, without changing SDK code? If so, we could disable the uart irq while initialization phase.

    You could implement specific error handling for specific errors.

    What would be an adequate error handling for

    1. APP_UART_COMMUNICATION_ERROR while initialization
    2. NRF_ERROR_RESOURCES while sending cyclic data with a broken connection

    Regards,
    Andi

  • Hello Andi,

    Andi_Frueh said:
    If I'm right, the connection intervall is defined in sdk_config.h with 7.5...30 ms. So we can decrease the disconnection timeout, as you suggested.

    Great! Yes, you could also set the two values to be equal, this will make the only possible connection interval whatever you define them too be. So long as this is fine with the peer (the central always decides, but the peripheral may be configured to disconnect if it does not support it), then this will always be the used connection interval. This also gives you a better predictability for how often the messages will be coming in.
    It also seems to me that you are here still using the 4000 ms connection supervision timeout, is this intentional or will you be lowering it later on?

    Andi_Frueh said:
    In main.c the uart buffer size is defined by 256 Byte. Increasing or decreasing this size has no effect to the disconnection detection. If the connection is broken, it takes around 4 seconds and the central runs into the error handle, before to detect disconnection.

    Does this means that it takes around 4 seconds for the UART buffer to overflow?
    Because if it is the 4 s connection timeout event will not cause it to enter the error handler, because a disconnection (for whatever reason) is not an application layer error. It is expected that a link may be broken at whatever time.
    If you decrease the connection supervision timeout to something much smaller, say 200 ms (with 7.5 ms connection interval this still gives you ~26 connection event tries to get your packets through before disconnecting), this would let you get the disconnected event much sooner. 

    Andi_Frueh said:

    What would be an adequate error handling for

    1. APP_UART_COMMUNICATION_ERROR while initialization

    This depends a little, but you could likely just ignore it during initialization unless this means that you are missing out on some critical / unique information. For example, you could ignore it until the UART peripheral is ready, clear the RX buffer, and then begin normal operation.

    Does your heartbeats contain any information, such as a timestamp or status?
    If they do not, you could for example just discard the information that is received during startup and wait for the next one.

    Andi_Frueh said:
    NRF_ERROR_RESOURCES while sending cyclic data with a broken connection

    This could also just be ignored in the case that you do not have any additional information contained in the heartbeat signal.
    For example if your hvn tx queue size is 1, there can only be queued a single heartbeat for sending at any one time. If the heartbeats come in every 250 ms, and you have a supervision timeout of < 250 ms, you will keep trying to send the same heartbeat notification up until either it goes through (and you then are ready for the next heartbeat) or until the connection is declared broken once the supervision timeout runs out.

    The important part for the error handling in both of these cases is that you do not use the default error handling, since this is to reset the device, which here would terminate the link and do no good.

    Best regards,
    Karl

Related