Finding Mac Bluetooth Addresses in Windows 10 UWP without Pairing

I am trying to write an application that reads all MAC addresses in Windows 10 IoT. These lines of code return all paired devices, even if they do not turn on.

var selector = BluetoothDevice.GetDeviceSelector(); var devices = await DeviceInformation.FindAllAsync(selector); listBox.Items.Add(devices.Count); foreach (var device in devices) { listBox.Items.Add(device.Id); } 

And I also found this line of code

 await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)); 

This returns null. Is there a way to scan all MAC addresses in a universal Windows 10 application?

+5
source share
2 answers

There is a new approach using the BluetoothLEAdvertisementWatcher to scan the entire Bluetooth LE device. Here is the code snippet that I use in my project:

 var advertisementWatcher = new BluetoothLEAdvertisementWatcher() { SignalStrengthFilter.InRangeThresholdInDBm = -100, SignalStrengthFilter.OutOfRangeThresholdInDBm = -102, SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(2000) }; advertisementWatcher.Received += AdvertisementWatcher_Received; advertisementWatcher.Stopped += AdvertisementWatcher_Stopped; advertisementWatcher.Start(); 

and later

 advertisementWatcher.Stop(); advertisementWatcher.Received -= AdvertisementWatcher_Received; advertisementWatcher.Stopped -= AdvertisementWatcher_Stopped; 
+2
source

You are very close to finding the answer to your question. You can try to get an instance of BluetoothDevice from the DeviceId property. You can then get all the specific Bluetooth information, including the Bluetooth address.

 var selector = BluetoothDevice.GetDeviceSelector(); var devices = await DeviceInformation.FindAllAsync(selector); foreach (var device in devices) { var bluetoothDevice = await BluetoothDevice.FromIdAsync(device.Id); if (bluetoothDevice != null) { Debug.WriteLine(bluetoothDevice.BluetoothAddress); } Debug.WriteLine(device.Id); foreach(var property in device.Properties) { Debug.WriteLine(" " + property.Key + " " + property.Value); } } 
+1
source

Source: https://habr.com/ru/post/1239292/


All Articles