Windows 10 - not receiving RuuviTag BLE advertisements

Hi all,

I received a new RuuviTag yesterday, and although I can receive the BLE advertisements on my iPhone in Ruuvi Station without any problems, my Windows 10 laptop does not seem to receive the same advertisements. I’m an experienced .NET developer, but this is my first time trying to do anything with BLE.

I’ve written a test app in C#/.NET 5.0 using the BluetoothLEAdvertisementWatcher class from the Windows SDK, and I’ve also tried using Microsoft’s Bluetooth LE Explorer app, and in both cases I do receive other advertisements (e.g. from nearby iPhone, TV, and so on), but I don’t see the advertisements from the RuuviTag.

My network card in the laptop is an Intel Wireless-AC 8625, which has Bluetooth 4.2 onboard. Bluetooth is otherwise functioning normally (I use a BT mouse and keyboard daily without any problems). In the Windows device manager, I can see that “Microsoft Bluetooth LE Enumerator” is listed under the Bluetooth devices, which I have read elsewhere as meaning that BLE should be operational. The RuuviTag itself is reporting that it is running the 2.5.9 firmware.

Before I start going down the route of buying a new Bluetooth dongle to try instead, does anyone have any other suggestions for things to try out, or if there is something fundamental that I might be overlooking about how BLE works?

Thanks!

EDIT: I was able to detect the sensor using an Ubuntu 20.04 Live USB and RuuviTag Sensor, so I can rule out the network card as the source of the problem.

EDIT 2: Success!

I must have been doing something stupid before, but I am now able to receive the advertisements in a .NET 5.0 app on Windows 10. For anyone else trying to do this on Windows 10 in the future, here’s a very quick start:

  1. In your project file, set the TargetFramework property to net5.0-windows10.0.19041.0 (for .NET 5.0 + Windows 10 2004 or later).
  2. Listen for advertisements as follows:
var watcher = new BluetoothLEAdvertisementWatcher();

var manufacturerData = new BluetoothLEManufacturerData() {
    // Manufacturer ID as per https://docs.ruuvi.com/communication/bluetooth-advertisements
    CompanyId = 0x0499
};

watcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(manufacturerData);

watcher.Received += (sender, args) => {
    Console.WriteLine($"Timestamp: {args.Timestamp}");
    
    IEnumerable<byte> macBytes = BitConverter.GetBytes(args.BluetoothAddress);
    if (BitConverter.IsLittleEndian) {
        macBytes = macBytes.Reverse();
    }
    var mac = string.Join(":", macBytes.Select(x => x.ToString("X2")));
    Console.WriteLine($"MAC Address: {mac}");

    foreach (var manufacturerData in args.Advertisement.ManufacturerData) {
        var data = new byte[manufacturerData.Data.Length];
        using (var reader = DataReader.FromBuffer(manufacturerData.Data)) {
            reader.ReadBytes(data);
        }
        Console.WriteLine($"Manufacturer ID: 0x{manufacturerData.CompanyId:X4}");
        Console.WriteLine($"Payload: {BitConverter.ToString(data)}");
    }

    Console.WriteLine();
};

watcher.Start();
2 Likes

Could you please share the full solution for this code. I have tried multiple options to try and get this snippet to work without any success and would really appreciate any help that you can give with getting this functionality to work.

Many thanks

Hi Karl,

Since I posted the snippet above I’ve actually written a set of libraries to simplify working with RuuviTag sensors in .NET. You can find all of the source code on GitHub here.

The key thing on Windows is to specify a target framework in your csproj that includes a Windows SDK targeting package, as this is what allows you to get access to the Bluetooth advertisement API. Microsoft documentation about this can be found here.

For the above snippet to target .NET 6 on Windows 10 version 2004 or later, the csproj file would be:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
</Project>

Many thanks for this … I will try this out and let you know how I get on. It looks like you have been to MS hell and back with this so I appreciate it that you have made your work public.

Regards

Karl Brennan