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

Reconnecting to a device fails

Hello,

We are developing using the S110 and having major trouble re-establishing Bluetooth connections to our device. The reason we need to reconnect to our device is to switch between application and bootloader mode to perform firmware updates. Here is our use case:

  1. Start out with our central (iOS/Android) connected to a peripheral running our custom service.

  2. Write to a characteristic on custom service that sets a "stay in bootloader" flag then calls sd_nvic_SystemReset.

  3. Wait for central to receive a disconnect event.

  4. Reconnect to the device (which is now in bootloader) using the previously known device ID.

  5. Discover the DFU service, then initiate an update.

  6. Again, wait for a disconnect event on the central because once DFU completes, it calls sd_nvic_SystemReset to start the new application firmware.

  7. Reconnect to the device (which is now in application) using the previously known device ID.

  8. Finally, rediscover our custom service, then clear the "stay in bootloader" flag.

Here are the problems we encounter:

On Android, the disconnect event takes several seconds. In order to avoid this delay, we tried deferring the sd_nvic_SystemReset until the peripheral receives a disconnect event. This allows the central (Android) to initiate the disconnect, instead of waiting for the event from the peripheral. However, this causes other problems...

There seems to be some ambiguity on both iOS and Android. When trying to reconnect right after a disconnect, sometimes the central seems to still be trying to connect to the bootloader when it should be connecting to the application and vice versa. Often times this connection will succeed, but then fail shortly afterward since the connection is actually stale.

We have taken care to make sure that our peripheral doesn't advertise anything when jumping between bootloader and application, so it's not clear why we would be seeing stale connections.

What is the best way to quickly and reliably disconnect from a device, jump between application or bootloader, then reconnect to it, on both iOS and Android?

Related