BLE Beacon Scanner Sample
Welcome to the BLE Beacon Scanner sample for Windows IoT. This sample demonstrates how to discover nearby Bluetooth Low Energy (BLE) beacons, read their advertising data, and display the information in a simple UI.
Getting Started
- Connect a compatible Windows IoT device (e.g., Raspberry Pi 4 with Windows 10 IoT Core).
- Enable Bluetooth on the device.
- Deploy the sample using Visual Studio.
- Run the app and start scanning for nearby beacons.
Code Overview
// MainPage.xaml.cs
using Windows.Devices.Bluetooth.Advertisement;
public sealed partial class MainPage : Page
{
private BluetoothLEAdvertisementWatcher watcher;
public MainPage()
{
this.InitializeComponent();
watcher = new BluetoothLEAdvertisementWatcher();
watcher.ScanningMode = BluetoothLEScanningMode.Active;
watcher.Received += OnAdvertisementReceived;
watcher.Start();
}
private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher sender,
BluetoothLEAdvertisementReceivedEventArgs args)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
var item = new BeaconInfo
{
Address = args.BluetoothAddress,
LocalName = args.Advertisement.LocalName,
Rssi = args.RawSignalStrengthInDBm,
Payload = BitConverter.ToString(args.Advertisement.ManufacturerData[0].Data.ToArray())
};
BeaconList.Items.Add(item);
});
}
}
The sample uses BluetoothLEAdvertisementWatcher to listen for BLE advertisements and updates a ListView with the detected beacons.