Proper sequence to disconnect BLE

Hi Nordic team,

I'm using nRF52832, S132 with nRF5_SDK_17.1.0_ddde560 SDK. I want to send a packet with a notification to my smartphone and then disconnect immediately. I have implemented write notify and disconnect commands successfully. However, I want to know if I can call a command to write to characteristic with notify, and then call the command to disconnect BLE immediately? Does this risk any data loss? Or should I wait a bit until the packet has been sent successfully and then disconnect?

I also have another question that is a bit out of topic. But is there any way we can ensure a packet sent from the BLE peripheral to the smartphone is received properly and isn't dropped along the way? Our application requires no data loss during transfer. Is there any step we need to take or the default SoftDevice BLE handles all of this and ensure data will be resent if it doesn't go through successfully?

Best regards,

Xander

Parents
  • Hi Xander,

    I will have to get back to you next week on whether the notification will be sent for sure before the disconnect happen.

    Your other question is rather on topic. If you want to ensure that the data is received by the smartphone, then you can use Indication instead of Notification. If very high throughput is not a concern, this is the best option.

    See:  How different BLE packet types influence throughput  

    Best regards,

    Hieu

  • Hi Hieu,

    After doing more research about indication and notification, I'm getting more confused now. I'm not sure if I misunderstood anything but here is how I understand. Let's assume BLE peripheral is NRF MCU, and BLE central is a smartphone.
    1. If I want to send data from a smartphone to the MCU, and I want the write with the response to ensure the write command goes through successfully, the MCU must have a write with response characteristic properties?
    2. If I want to send data from MCU to the smartphone, and ensure no data loss, the MCU must have a read indication characteristic properties? Smartphones don't have to poll data so that's why I used to read notify in the past. I'm not sure if I can replace read notify with just read indication.

    If possible, can you guide me with some resources to learn how to use these properties properly?


    Best regards,

    Xander

  • Hi Xander,

    Central and Peripheral are GAP concepts. When you are dealing with characteristics, you are dealing with GATT, and the roles are GATT Client and GATT Server.

    In the vast majority of cases, the smartphone is the GAP Central and also the GATT Client, and a BLE device is the GAP Peripheral and also the GATT Server.

    Xander To said:
    1. If I want to send data from a smartphone to the MCU, and I want the write with the response to ensure the write command goes through successfully, the MCU must have a write with response characteristic properties?

    Almost yes. To be precise, the characteristic being written must have the Write with Response properties.

    Xander To said:
    2. If I want to send data from MCU to the smartphone, and ensure no data loss, the MCU must have a read indication characteristic properties? Smartphones don't have to poll data so that's why I used to read notify in the past. I'm not sure if I can replace read notify with just read indication.

    Read, Notify, and Indicate are three different independent properties. Independent meaning they are not in any way mutually exclusive or implicative.
    They should be set according to what you want to enable and what you want to forbid.

    Xander To said:
    If possible, can you guide me with some resources to learn how to use these properties properly?

    This is pretty good: https://novelbits.io/bluetooth-gatt-services-characteristics/

    Best regards,

    Hieu

  • Hi Hieu,

    I have checked out the link you sent. I believe that writing with the response is the property required to ensure no data loss when a smartphone wants to send data to the MCU, and reading with indication is the property required to ensure no data loss when the MCU sends data to a smartphone, am I correct?

    Furthermore, if I want a smartphone or any client-side to read the data from MCU without polling, I must add notify properties to the characteristic. So in the end, I must use read notify indication characteristic?

    Best regards,

    Xander

Reply
  • Hi Hieu,

    I have checked out the link you sent. I believe that writing with the response is the property required to ensure no data loss when a smartphone wants to send data to the MCU, and reading with indication is the property required to ensure no data loss when the MCU sends data to a smartphone, am I correct?

    Furthermore, if I want a smartphone or any client-side to read the data from MCU without polling, I must add notify properties to the characteristic. So in the end, I must use read notify indication characteristic?

    Best regards,

    Xander

Children
  • Hi Xander,

    Xander To said:
    I have checked out the link you sent. I believe that writing with the response is the property required to ensure no data loss when a smartphone wants to send data to the MCU, and reading with indication is the property required to ensure no data loss when the MCU sends data to a smartphone, am I correct?

    Yes

    Xander To said:
    Furthermore, if I want a smartphone or any client-side to read the data from MCU without polling, I must add notify properties to the characteristic. So in the end, I must use read notify indication characteristic?

    Indication also let the client read without polling. It just requires a response from the client in the next connection event and is therefore slower than Notification.

    Best regards,

    Hieu

Related