Search code examples
c#winformsbluetoothwindows-10rssi

Bluetooth scan C#


I'm developing a C# WinForms app on Windows 10. I want to perform a Bluetooth environment scan and get devices list all around the PC. I also want the RSSI of each device.

I have tried 32feet library but I can't access RSSI.

Have you a solution or should I migrate to WPF/UWP?


Solution

  • ok, I have found a solution here.

    1. You first have to install Windows10 development kit.
    2. Then in your project you have to add this library:

      C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
      

      Or you can install the "UwpDesktop" NuGet Package.

    3. This works with Console app, Winforms, WPF and UWP.

    4. Here is a simple example:

      using Windows.Devices.Bluetooth.Advertisement;
      
      namespace BeaconExample
      {
          class Program
          {
              static void Main(string[] args)
              {
                  var watcher = new BluetoothLEAdvertisementWatcher();
                  watcher.Received += Watcher_Received;
                  watcher.Start();
              }
      
              private static void Watcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
              {
                  Console.WriteLine(args.BluetoothAddress.ToString("x") + ";" + args.RawSignalStrengthInDBm);
              }
          }
      }