public static void UnpairByName(string name, int discoveryTime, Utils.DeviceType deviceType) { var devices = DeviceFinder.FindDevicesByName(DeviceDiscoverer.DiscoverPairedBluetoothDevices(discoveryTime), name, deviceType); if (devices.Count > 1) { throw new Exception($"{devices.Count} devices found, don't know which one to choose"); } DevicePairer.UnpairDevice(devices[0]); }
public async void UnpairWithMac(string deviceId) { DeviceInformation devInfo = await DeviceInformation.CreateFromIdAsync(deviceId); try { DevicePairer.UnpairDevice(new Device(devInfo)); } catch (Exception ex) { Log.V($"UnpairWithMac(): Exception, message={ex.Message}"); } }
private static async Task <bool> HandleSituation_2_BluetoothLe_devices_with_the_same_name_found(Device device1, Device device2, string pin) { // BLuetooth LE devices use mac randomization, which can lead to the situation when // the user already have the device paired but with different mac address. // In this situation we need to unpair the old device and pair the current one. // If we don't unpair the old device first, the pairing procedure will fail. if (device1.IsPaired || device2.IsPaired) { var oldDevice = device1.IsPaired ? device1 : device2; var newDevice = !device1.IsPaired ? device1 : device2; Console.WriteLine($"2 devices with the same name found: \"{oldDevice}\" (paired) and \"{newDevice}\""); Console.WriteLine("Assume that the device changed its mac address"); DevicePairer.UnpairDevice(oldDevice); return(await DevicePairer.PairDevice(newDevice, pin)); } throw new Exception($"2 unpaired devices with the same name found \"{device1}\" \"{device2}\". Don't know which one to choose."); }
public void UnpairByMac(string mac) { Utils.ValidateMac(mac); _pairer.UnpairDevice(_finder.FindDeviceByMac(_discoverer.DiscoverDevices(), mac)); }