Connection with Central and Peripheral using different MTU size

Hi,

My device works as a central and peripheral both but not at a same time as of now. According to my use case, I have the following connection scenario.

  1. It should connect (as a peripheral) with phone app (as a central) and work for data exchange with 240bytes MTU
  2. It should connect (as a central) with beacon (as a peripheral) and work for data exchange with 20 (BLE4) and 240bytes (BLE5) MTU according to beacon type.

I just want to know what type of changes I should make in SDK so that it fulfills both above scenarios.

Regards,

Bipin Patel

  • The change of MTU size has been discussed in this forum, like this thread  The link of the thread will help you answer the first point where you need to change the MTU size for one connection.

    Not sure what you mean by connecting to the beacon? Beacons do not connect to anything, but if you want to connect to different peripheral with different MTU sizes, then it should not be a problem. In BLE, you can connect to different peripheral with different MTU sizes, given that the MTU size is smaller or equal to the maximum MTU size the controller can handle.

    I would recommend you to go through this sample to understand how we fine tune the connection with MTU size and other connection parameters to get maximum throughput. Even though your goal is not focusing on  max throughput, the sample will give you some understanding on how to change the MTU size atleast.

  • Hi Susheel,

    Thanks for sharing your input.

    We were trying to achieve our mentioned use case by setting the following Macros.

    #define NRF_SDH_BLE_GATT_MAX_MTU_SIZE      243

    #define NRF_SDH_BLE_GAP_DATA_LENGTH       247

    #define BLE_GATT_ATT_MTU_DEFAULT          23

    But I was getting NRF_ERROR_BUSY error while calling sd_ble_gattc_primary_services_discover in BLE_GAP_EVT_CONNECTED event when device is working as a central.  After some searching on Devzone regarding this, we found one post below with a similar issue. 

    https://devzone.nordicsemi.com/f/nordic-q-a/37125/nrf_error_busy-from-sd_ble_gattc_primary_services_discover

    In which, there is a suggestion of keeping 3 second delay before calling sd_ble_gattc_primary_services_discover after BLE_GAP_EVT_CONNECTED event. I have tried it and I am not getting NRF_ERROR_BUSY error now.

    My question is whether it is a proper way to handle it or temporary work around?

    Regards,

    Bipin Patel

  • karanbakshi said:
    My question is whether it is a proper way to handle it or temporary work around?

    Hi Karan, If you see that there was some BLE activity after getting connected and before you start your service discovery, then it is understandable that you were trying to initiate another procedure in midst of an already ongoing procedure. If you do a sniffer trace and get the activity right after connection you will be able to determine the cause for the softdevice to reject starting a procedure of service discovery right after the connection. Not sure if 3 seconds is optimal but if your application can accept 3 seconds of delay to start the service discovery, this workaround does not look bad.

  • Hi Susheel,

    Is any way to check any pending BLE activities after BLE connection to start service discovery so that we can avoid this delay?

    Regards,

    Bipin Patel

  • Sorry Karan for late response. A sniffer trace on the BLE activity would give you a lot of insights on what is happening right after the connection. You should be able to see which procedure starts with all the timing info. Have you tried sniffing your BLE connection?

Related