Post

Replies

Boosts

Views

Activity

Reply to BLE: Can not connect to device with service UUID and characteristic UUID?
Addition information from log: For first device: isBluetoothAvailable() scan() CentralManager( central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) (peripheral <CBPeripheral: 0x267hg5670, identifier = 98HG761CE-56C3-K767-26HJ-E51BA678Gh56, name = DeviceOne, state = disconnected) CentralManager( central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) scan() CentralManager( central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) (peripheral <CBPeripheral: 0x267hg5670, identifier = FJ1478HJ-EH8J-6709-1FH0-1456HGJ0BC901, name = SecondDevice, state = disconnected>) stopScan() connect(peripheral: CBPeripheral) (currentPeripheral nil, currentPeripheral nil) CentralManager( central: CBCentralManager, didConnect peripheral: CBPeripheral centralManager(:didConnect:) - didConnectPeripheral FJ1478HJ-EH8J-6709-1FH0-1456HGJ0BC901 Second device savedPeripheralString FJ1478HJ-EH8J-6709-1FH0-1456HGJ0BC901 Second device Bluetooth stop() currentPeripheral Optional(<CBPeripheral: 0x2jk875fe0, identifier = FJ1478HJ-EH8J-6709-1FH0-1456HGJ0BC901, name = SecondDevice, state = connected>) disableSleep() peripheral( peripheral: CBPeripheral, didDiscoverServices error: Error?) peripheral(:didDiscoverServices:) - didDiscoverServices for peripheral FJ1478HJ-EH8J-6709-1FH0-1456HGJ0BC901 peripheral(:didDiscoverServices:) - didDiscoverServices for peripheral.services Optional([<CBService: 0x2jkki2dc0, isPrimary = YES, UUID = 59DE3994-6A63-4654-8FF0-F85C5163B2F5>, <CBService: 0xhj67c240, isPrimary = YES, UUID = Device Information>]) [<CBService: 0x5678f2dc0, isPrimary = YES, UUID = 59DE3994-6A63-4654-8FF0-F85C5163B2F5>, <CBService: 0x28186c240, isPrimary = YES, UUID = Device Information>], peripheral.services is Optional([<CBService: 0xhjy62dc0, isPrimary = YES, UUID = 59DE3994-6A63-4654-8FF0-F85C5163B2F5>, <CBService: 0x2hju7240, isPrimary = YES, UUID = Device Information>])) service.uuid.uuidString is 59DE3994-6A63-4654-8FF0-F85C5163B2F5 and services is [<CBService: 0xhj7892dc0, isPrimary = YES, UUID = 59DE3994-6A63-4654-8FF0-F85C5163B2F5>, <CBService: 0xhjk678340, isPrimary = YES, UUID = Device Information>] peripheral(:didDiscoverServices:) - didDiscoverServices SecondDevice 59DE3994-6A63-4654-8FF0-F85C5163B2F5 peripheral(:didDiscoverServices:) - didDiscoverServices for peripheral not found FJ1478HJ-EH8J-6709-1FH0-1456HGJ0BC901 For second device: isBluetoothAvailable() scan() CentralManager( central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) (peripheral <CBPeripheral: 0xh6789a40, identifier = 98HG761CE-56C3-K767-26HJ-E51BA678Gh56, name = DeviceOne, state = disconnected) scan() CentralManager( central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) (peripheral <CBPeripheral: 0x678jhs0, identifier = H56KIL35-7835-7JKL-2B11-HJKLIYTAA400, name = ThirdDevice, state = disconnected) CentralManager( central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) stopScan() connect(peripheral: CBPeripheral) currentPeripheral nil, currentPeripheral nil CentralManager( central: CBCentralManager, didConnect peripheral: CBPeripheral centralManager(:didConnect:) - didConnectPeripheral H56KIL35-7835-7JKL-2B11-HJKLIYTAA400 savedPeripheralString H56KIL35-7835-7JKL-2B11-HJKLIYTAA400 Bluetooth stop() - currentPeripheral Optional(<CBPeripheral: 0x78jkl680, identifier = H56KIL35-7835-7JKL-2B11-HJKLIYTAA400, name = ThirdDevice, state = connected>) disableSleep() peripheral( peripheral: CBPeripheral, didDiscoverServices error: Error?) peripheral(:didDiscoverServices:) - didDiscoverServices for peripheral H56KIL35-7835-7JKL-2B11-HJKLIYTAA400 peripheral(:didDiscoverServices:) - didDiscoverServices for peripheral.services Optional([<CBService: 0xlki8901c0, isPrimary = YES, UUID = 59DE3994-6A63-4654-8FF0-F85C5163B2F5 - same like for secondDevice>, <CBService: 0x281111180, isPrimary = YES, UUID = Device Information>]) services is [<CBService: 0x2827444c0, isPrimary = YES, UUID = 59DE3994-6A63-4654-8FF0-F85C5163B2F5 - same like for secondDevice>, <CBService: 0x282744580, isPrimary = YES, UUID = Device Information>], peripheral.services is Optional([<CBService: 0xlki8901c0, isPrimary = YES, UUID = 59DE3994-6A63-4654-8FF0-F85C5163B2F5 - same like for secondDevice>, <CBService: 0x281111180, isPrimary = YES, UUID = Device Information>])) service.uuid.uuidString is 59DE3994-6A63-4654-8FF0-F85C5163B2F5 - same like for secondDeviceand services is [<CBService: 0x27893kdc0, isPrimary = YES, UUID = 59DE3994-6A63-4654-8FF0-F85C5163B2F5 - same like for secondDevice>, <CBService: 0x679kh8580, isPrimary = YES, UUID = Device Information>] peripheral(:didDiscoverServices:) - didDiscoverServices ThirdDevice 59DE3994-6A63-4654-8FF0-F85C5163B2F5 - same like for secondDevice peripheral(:didDiscoverServices:) - didDiscoverServices for peripheral not found H56KIL35-7835-7JKL-2B11-HJKLIYTAA400 Based on logs information in peripheral(_:didDiscoverServices:) - didDiscoverServices, app connected to my first service UUID and first characteristic UUID, that is wrong! Can not understand how this is possible. Thanks any help!
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21