     
     
     public func startPairing() {
-        isPairing = true
-        
-        guard peripheralManager.state == .poweredOn, centralManager.state == .poweredOn else { return }
-        
-        let service = CBMutableService(type: serviceId, primary: true)
-        service.characteristics = [pairingStatusCharacteristic]
-        
-        peripheralManager.add(service)
-        centralManager.scanForPeripherals(withServices: [serviceId], options: nil)
-        status = .scanning
+        if peripheralManager.state == .poweredOn, centralManager.state == .poweredOn {
+            let service = CBMutableService(type: serviceId, primary: true)
+            service.characteristics = [pairingStatusCharacteristic]
+            
+            peripheralManager.add(service)
+            centralManager.scanForPeripherals(withServices: [serviceId], options: nil)
+            status = .scanning
+        } else {
+            Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in
+                self.startPairing()
+            }
+        }
     }
     
     public func cancelPairing() {

}


extension PairingTask: CBPeripheralDelegate {
    public func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: Error?) {
        guard peripheral.identifier == remotePeripheral?.identifier else { return }

    
    fileprivate var serviceId = CBUUID(string: "7D912F17-0583-4A1A-A499-205FF6835514")
    fileprivate var remotePeripheral: CBPeripheral? = nil
    fileprivate var pairingStatusCharacteristic = CBMutableCharacteristic(
        type: CBUUID(string: "ECC2D7D1-FB7C-4AF2-B068-0525AEFD7F53"),
        properties: .notify,
