NordicSemiconductor / IOS-DFU-Library

OTA DFU Library for Mac and iOS, compatible with nRF5x SoCs
http://www.nordicsemi.com
BSD 3-Clause "New" or "Revised" License
525 stars 214 forks source link

Stuck in "Connecting" but already connected #403

Closed connyhald closed 3 years ago

connyhald commented 3 years ago

Doing a firmware update of our peripheral from Android works fine. However on iOS the DFU process is stuck at a very early phase.

We are using Secure Buttonless DFU with our own control characteristic.

We first connect our device, then we hit a "Start DFU" button. On Android the lib now writes to the control characteristic which will reboot the device into the bootloader. On iOS basically nothing happens. We get one single log entry. The device stays connected and that's it.

dfuStateDidChange(): Connecting

I think the lib should not try to connect, because the peripheral is already connected. Using the debugger I can see, that things go wrong in DFUPeripheral.start().

        // Set the initial peripheral. It may be changed later (flashing App fw
        // after first flashing SD/BL).
        guard let peripheral = centralManager
            .retrievePeripherals(withIdentifiers: [targetIdentifier]).first else {
            delegate?.error(.bluetoothDisabled, didOccurWithMessage:
                "Could not obtain peripheral instance")
            return
        }
        self.peripheral = peripheral

        if peripheral.state != .connected {
            connect()   // <<<<<<<<<<<<<<<<< We end up here, but shouldn't
        } else {
            let name = peripheral.name ?? "Unknown device"
            //....
        }

For some reason peripheral.state == .connected while still in our code. But if we enter library code the peripheral which is received by centralManager.retrievePeripherals is not connected but still has the correct name, so it seems to be the correct peripheral.

Does anyone here has some insights on that behavior?

DFU Bootloader version

Device information

connyhald commented 3 years ago

We've now switched from SwiftPackageManager to CocoaPods so that we could add some logging.

As it turns out we're ending up here: https://github.com/NordicSemiconductor/IOS-Pods-DFU-Library/blob/d4a1da27fbf195b325cea3036235a4939a8f4efa/iOSDFULibrary/Classes/Implementation/GenericDFU/DFUPeripheral.swift#L370

The strange thing is, that all those logger calls do not log anything for us which is odd, because we do implement the LoggerDelegate protocol.

Anyways there are different issue and I'll open different tickets if needed.