I am developing a UWP application using bluetooth to connect to various devices.
My problem is that some devices that have been paired or previously detected appear in my device list, even if they are disconnected or not in range.
In my opinion, the System.Devices.Aep.IsPresent property can be used to filter cached devices that are not available on but I always get "True" for this property, although I know that the device is not available.
Any ideas on how this can be resolved?
Customization
string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected", "System.Devices.Aep.IsPresent", "System.Devices.Aep.ContainerId", "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.Manufacturer", "System.Devices.Aep.ModelId", "System.Devices.Aep.ProtocolId", "System.Devices.Aep.SignalStrength"};
_deviceWatcher = DeviceInformation.CreateWatcher("{REMOVED, NOT IMPORTANT}", requestedProperties, DeviceInformationKind.AssociationEndpoint);
_deviceWatcher.Added += DeviceAdded;
_deviceWatcher.Updated += DeviceUpdated;
_deviceWatcher.Removed += DeviceRemoved;
_deviceWatcher.EnumerationCompleted += DeviceEnumerationCompleted;
Add device callback
Here isPresent is always true
private void DeviceAdded(DeviceWatcher sender, DeviceInformation deviceInfo)
{
Device device = new Device(deviceInfo);
bool isPresent = (bool)deviceInfo.Properties.Single(p => p.Key == "System.Devices.Aep.IsPresent").Value;
Debug.WriteLine("*** Found device " + deviceInfo.Id + " / " + device.Id + ", " + "name: " + deviceInfo.Name + " ***");
Debug.WriteLine("RSSI = " + deviceInfo.Properties.Single(d => d.Key == "System.Devices.Aep.SignalStrength").Value);
Debug.WriteLine("Present: " + isPresent);
var rssi = deviceInfo.Properties.Single(d => d.Key == "System.Devices.Aep.SignalStrength").Value;
if (rssi != null)
device.Rssi = int.Parse(rssi.ToString());
if (DiscoveredDevices.All(x => x.Id != device.Id) && isPresent)
{
DiscoveredDevices.Add(device);
DeviceDiscovered(this, new DeviceDiscoveredEventArgs(device));
}
}