Client automatically reconnects to server after OTA DFU

I'm trying to implement OTA DFU in our custom App with our nRF52832 acting as the device to be upgraded.  Everything seems to work OK in that:

1. New image uploads to the device

2. App resets the device to transfer new image into correct area

3. App does a check to ensure the new image is OK, then confirms this with the device

4. App forces another software reset on the device

At this point, the device should start advertising again.  But for some reason it stays connected to the client.  I'm trying to work out how to prevent this happening, primarily as my App is only scanning for devices and grabbing the scan response data to update its info.  It only needs to connect when its going to do an OTA DFU.  But because it remains connected after the OTA DFU, things get all locked up.

Not sure if this needs to be driven from the client or the server side.  Client is an iOS device running our custom App.  I am also using the CTS on the server, so client and server are paired at some point.  I believe this is a requirement by Apple for devices to access CTS on an iOS device.

Any ideas how I can ensure that the client doesn't automatically reconnect to the server after the final reset at the completion of the OTA DFU?

Cheers,

Mike

  • Hi Mike, 

    I will check with the app team to see if there is any solution. 

    But could you let me know, if you turn on the device (in normal operation) close to the phone, would they automatically connect ? 
    As far as I know if a paired device is in range, the phone may just re-connect to it automatically. 

  • Hi Hung,

    Thanks.

    So, in "normal" operation, the device is advertising, but the App doesn't try and connect.  It just grabs the scan response data and updates its info that way.  The only time it will connect is to do a DFU.

    I do notice that if I connect to the device using any other iOS BLE app (nRF Connect, LightBlue, etc) then when I hit the "disconnect" button on those apps, the Central doesn't actually disconnect from Peripheral.  I actually had to create a characteristic that I have to write to in order to force the disconnection from those Apps.  This might be something to do with iOS - I'm not sure.

    But after the DFU and with my custom App forcing the software reset, I would have thought the Peripheral would disconnect.  If I do a reset on the DK, it certainly forces the disconnect.  But having my App force the reset, it doesn't seem to.

    I grab the vallue of RESETREAS when it first boots up, and not surprisingly, when the App resets the device, I see RESETREAS = 0x04, which corresponds to the Software Reset (SREQ).  My code then sets up Bluetooth and starts advertising.  The Client then connects, even though I don't want it to.

    If I do a RESETPIN reset via the button on my DK at this point, then the device will go through the Bluetooth start up and start advertising, but will not reconnect to the Central.

    The brute force method at this point might well be that my App needs to write to my "disconnect" characteristic to force a disconnect.

    Cheers,

    Mike

  • Thanks Mike. 
    I think this is something we can fix in the iOS DFU library. I assume you have the same problem when you test with nRF DFU app or nRF Toolbox app , correct ? 
    I will report your observation to the app team and will let you know when we have any update. 

  • Hello  

    I believe that you're using nRF5 SDK, not NCS, therefore OTA over Secure or Legacy DFU. Could you write which SDK version?

    Either way, in both legacy and secure dfu, the update is performed by the dfu bootloader. The last command sent after upload is complete triggers device restart, initiated from the device side. Mobile dfu libraries report succees only after the device disconnects. The device then switches back to application mode.

    As I understand, your device has Current Time Service (CTS). iOS it a requirement for the project? It's not required by iOS, it exposes it's own CTS service, but there's no need to use it.

    Are you using pairing or bonding? I believe, after the restart it's starting direct advertising which may triggers automatic reconnection from the phone. iOS can support CTS service natively, so may hold the connection writing any app running.

    But because it remains connected after the OTA DFU, things get all locked up.

    Is it connected to the bootloader, or your custom firmware?

    Also, the mobile dfu libs are generating logs. It would be very helpful to see them. I believe that the dfu operation ends with a restart and it is the advertising initiated by firmware that triggers the phone to reconnect, but logs could prove me being wrong.

  • I do notice that if I connect to the device using any other iOS BLE app (nRF Connect, LightBlue, etc) then when I hit the "disconnect" button on those apps, the Central doesn't actually disconnect from Peripheral.  I actually had to create a characteristic that I have to write to in order to force the disconnection from those Apps.  This might be something to do with iOS - I'm not sure.

    This is expected behavior. A device on both Android and iOS can be connected by multiple apps or multiple clients in each app. The physical Le connection is terminated only when the last virtual connection is discontented. A virtual connection may also be held by the system, if is supports the service, e.g. HID, or, in case of iOS, perhaps CTS service. A command to trigger disconnection from the device side is indeed the only solution for this use case.

    However, I understand that it is the automatic reconnection, not lack of disconnection, that's the root cause. Try disabling direct advertising, or the CTS service, if you don't need it.

    If connection is only for dfu, why do you have pairing/bonding in the first place?

Related