3

BLE works fine on 7 Plus (iOS 14.4.2) and 6 (iOS 12). But on XR (14.4.2) and 11 connection stuck after centralManager.connect(peripheral, options: nil) (infinite connection)

The peripheral is in connection mode because other smartphones cannot detect it. At first I thought that the problem was with the radio module of the peripheral device itself (NRF52), but the problem also occurred with the debug board. Rebooting the smartphone did not help. It's funny that the app works fine on a MacBook with an M1 chip

Part of code:

// Peripheral model

init(withPeripheral peripheral: CBPeripheral, advertisementData advertisementDictionary: [String : Any], andRSSI currentRSSI: NSNumber, using manager: CBCentralManager) {
    centralManager = manager
    basePeripheral = peripheral
    RSSI = currentRSSI
    super.init()
    advertisedName = parseAdvertisementData(advertisementDictionary)
    basePeripheral.delegate = self
}

public func connect() {
    centralManager.delegate = self
    centralManager.connect(basePeripheral, options: nil)
    print("Connecting to \(advertisedName ?? "device")...") 
// logs stops here
}

public func disconnect() {
    centralManager.cancelPeripheralConnection(basePeripheral)
    print("Cancelling connection with \(advertisedName ?? "device")...")
// triggers on VC dismiss
}

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    if central.state != .poweredOn {
        print("Central Manager stated changed to \(central.state)")
    }
}

func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
    if peripheral == basePeripheral {
        print("Connected to \(advertisedName ?? "device")")
        delegate?.peripheralDidConnect()
        discoverPrimaryServices()
    }
}

func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
    if peripheral == basePeripheral {
        print("Disconnected from \(advertisedName ?? "device")")
        delegate?.peripheralDidDisconnect()
    }
}
Tim Yumalin
  • 420
  • 5
  • 14

1 Answers1

4

"The peripheral is in connection mode because other smartphones cannot detect it." Did you mean that other smartphones can detect it?

Given the phones you've listed as working and not working, I would expect that your board is having trouble with Bluetooth 5 (which was first supported on the iPhone 8). The NRF52 supports BT5 (it supports 5.2), but if you've written your own firmware you may have broken the support. I'd start by making sure you're running the most vanilla code you can from Nordic.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • I meant that the peripheral device disappears from the scanners when it freezes at the stage of connecting to a smartphone i.e. it seems to be working normally without errors and disconnections, it simply cannot fully connect on some devices. I wrote my code based on the nRF Blinky application, of course it was quite heavily modified, but the foundation and general patterns remained unchanged. In fact, I replaced the UUID services and characteristics and added many of my own. You said that the problem may be in the firmware of the board itself, I'll try to look for the problem there, thank you – Tim Yumalin May 19 '21 at 05:38
  • 1
    So we installed the original firmware for the NRF52 (UART), on the basis of which our software was written and the connection was successful, and apparently the problem is really on the side of the peripheral device. Thanks for the hint! – Tim Yumalin May 19 '21 at 07:12