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

Handover DFU connection

Hi,

Instead of initiating the DFU library in Android with an address is it possible to handover a existing GATT connection to a device already in DFU mode?

We have cases where we in our app is detecting devices in DFU mode. We haven't experienced any problems connecting to those from our app but we have experience many problems disconnecting the device and handing over address to DFU library for connection. We have moved to DFU v1.3 and have seen some commits laborating with sleep time, but still we randomly experience problems. Doing re-retries will eventually fix the problem but gives a bad user experience.

Parents
  • Hi Daniel,

    You don't have to disconnect in your app before starting DFU. You will eventually get the onConnectionStateChanged callback with newState=DISCONNECTED when you just start the DFU. On Android every app may have a number of BluetoothGatt connections to a device. They all behave as they were the only one, but it doesn't have to be true. The physical connection will be terminated when the last one of those is disconnected.

    So what you may do is, when you connect to your device (no matter if it's in bootloader on in app mode), just start DFU providing the device address, as you do right now. The BluetoothGatt object of BluetoothGattCallback can't be passed to the service, so handing over the existing connection object is not possible, but when you won't disconnect before starting DFU the same physical connection will be used. Some time after you started DFU you may disconnect, when the library has already created its own connection object, but also you don't have to. When DFU is completed (or the first part of it) you'll get the disconnected event as it the device just disconnected itself. You may actually sniff the packets in your app, your connection, sent by the device during DFU by calling setNotificationsEnabled(DFU Control Point char, true), but it may add some delays and I wouldn't recommend it.

    Hope that helped.

    BR, Aleksander

Reply
  • Hi Daniel,

    You don't have to disconnect in your app before starting DFU. You will eventually get the onConnectionStateChanged callback with newState=DISCONNECTED when you just start the DFU. On Android every app may have a number of BluetoothGatt connections to a device. They all behave as they were the only one, but it doesn't have to be true. The physical connection will be terminated when the last one of those is disconnected.

    So what you may do is, when you connect to your device (no matter if it's in bootloader on in app mode), just start DFU providing the device address, as you do right now. The BluetoothGatt object of BluetoothGattCallback can't be passed to the service, so handing over the existing connection object is not possible, but when you won't disconnect before starting DFU the same physical connection will be used. Some time after you started DFU you may disconnect, when the library has already created its own connection object, but also you don't have to. When DFU is completed (or the first part of it) you'll get the disconnected event as it the device just disconnected itself. You may actually sniff the packets in your app, your connection, sent by the device during DFU by calling setNotificationsEnabled(DFU Control Point char, true), but it may add some delays and I wouldn't recommend it.

    Hope that helped.

    BR, Aleksander

Children
No Data
Related