Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.System;

using Windows.Devices.Bluetooth.Advertisement;

namespace ConsoleApplication1
{
class Program
internal class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
// Start the program
var program = new Program();

// Close on key press
Console.ReadLine();
Console.WriteLine("Scanning ... Press any key to cancel (finish).");
Console.ReadKey();
}

public Program()
Expand All @@ -33,13 +28,16 @@ public Program()
// Stop watching if the value drops below -90 (user walked away)
watcher.SignalStrengthFilter.OutOfRangeThresholdInDBm = -90;

// Register callback for when we see an advertisements
watcher.Received += OnAdvertisementReceived;

// Wait 5 seconds to make sure the device is really out of range
watcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(5000);
watcher.SignalStrengthFilter.SamplingInterval = TimeSpan.FromMilliseconds(2000);

// Register callback for when we see an advertisements
watcher.Received += OnAdvertisementReceived;

// Register callback for scan stop or error, especially
watcher.Stopped += OnStopped;

// Starting watching for advertisements
watcher.Start();
}
Expand All @@ -52,5 +50,12 @@ private void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, Bl
Console.WriteLine(String.Format(" FR_NAME: {0}", eventArgs.Advertisement.LocalName));
Console.WriteLine();
}

private void OnStopped(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementWatcherStoppedEventArgs args)
{
// Tell the user when the advertisement finishes
Console.WriteLine(String.Format("Advertisement stopped with: {0}", args.Error));
Console.WriteLine("Press any key to finish.");
}
}
}
}