Skip to content

Commit 05cc334

Browse files
committed
Added more BLE debugging log points to try to sniff out a bug keeping one user from connecting to their device.
1 parent 4a816c2 commit 05cc334

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

Infini-iOS/BLE/BLEDelegates.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,29 @@ import CoreBluetooth
1313

1414
extension BLEManager: CBPeripheralDelegate {
1515
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
16-
guard let services = peripheral.services else { return }
16+
guard let services = peripheral.services else {
17+
if error != nil {
18+
bleLogger.debug(error: "Unable to discover services for device '\(peripheral.name!)'. Error message: \(error!)", log: .ble, date: Date())
19+
} else {
20+
bleLogger.debug(error: "Unable to discover services for device '\(peripheral.name!)'.", log: .ble, date: Date())
21+
}
22+
return
23+
}
1724

1825
for service in services {
1926
peripheral.discoverCharacteristics(nil, for:service)
2027
}
2128
}
2229

2330
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
24-
guard let characteristics = service.characteristics else { return }
31+
guard let characteristics = service.characteristics else {
32+
if error != nil {
33+
bleLogger.debug(error: "Unable to discover characteristics for device '\(peripheral.name!)'. Error message: \(error!)", log: .ble, date: Date())
34+
} else {
35+
bleLogger.debug(error: "Unable to discover characteristics for device '\(peripheral.name!)'.", log: .ble, date: Date())
36+
}
37+
return
38+
}
2539

2640
for characteristic in characteristics {
2741
DeviceInfoManager().readInfoCharacteristics(characteristic: characteristic, peripheral: peripheral)
@@ -32,5 +46,8 @@ extension BLEManager: CBPeripheralDelegate {
3246
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
3347
DeviceInfoManager().updateInfo(characteristic: characteristic)
3448
BLEUpdatedCharacteristicHandler().handleUpdates(characteristic: characteristic, peripheral: peripheral)
49+
if error != nil {
50+
bleLogger.debug(error: "Unable to update value for device '\(peripheral.name!)'. Error message: \(error!)", log: .ble, date: Date())
51+
}
3552
}
3653
}

Infini-iOS/BLE/BLEManager.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
129129

130130
setAutoconnectUUID = peripheral.identifier.uuidString
131131
isConnectedToPinetime = true
132+
} else {
133+
DebugLogManager.shared.debug(error: "Could not connect to device not named 'InfiniTime'. Device name: \(peripheral.name!)", log: .ble, date: Date())
132134
}
133135
}
134136

@@ -145,7 +147,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
145147
let newPeripheral = Peripheral(id: peripheralDictionary.count, name: peripheralName, rssi: RSSI.intValue, peripheralHash: peripheral.hash, deviceUUID: devUUID, stringUUID: peripheral.identifier.uuidString)
146148

147149
guard BLEAutoconnectManager.shared.connect(peripheral: peripheral) else {
148-
// compare peripheral UUIDs to make sure we're only adding each device once -- super helpful if you have a very noisy BLE advertiser nearby!
149150
if !peripherals.contains(where: {$0.deviceUUID == newPeripheral.deviceUUID}) {
150151
peripherals.append(newPeripheral)
151152
peripheralDictionary[newPeripheral.peripheralHash] = peripheral
@@ -165,6 +166,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
165166
self.infiniTime.discoverServices(nil)
166167
DeviceInfoManager().setDeviceName(uuid: peripheral.identifier.uuidString)
167168
UptimeManager.shared.connectTime = Date()
169+
bleLogger.debug(error: "Successfully connected to \(peripheral.name!)", log: .ble, date: Date())
168170
}
169171

170172
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {

0 commit comments

Comments
 (0)