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:
- In your project file, set the
TargetFramework
property tonet5.0-windows10.0.19041.0
(for .NET 5.0 + Windows 10 2004 or later). - 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();