在Windows 10上连接到BLE外围设备

Mar*_*sek 1 windows bluetooth

我尝试连接到BLE外围设备。首先,我看广告:

watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active };
watcher.Received += WatcherOnReceived;
watcher.Start();
Run Code Online (Sandbox Code Playgroud)

在WatcherOnReceived回调中,我尝试创建BluetoothLEDevice

public async void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs btAdv)
{
    BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress);
}
Run Code Online (Sandbox Code Playgroud)

但是,我总是在WatcherOnReceived回调中得到bleDevice == null。为什么以及如何解决?在UWP应用程序中创建BLE设备的正确方法是什么?然后,我需要连接到该设备,发现其GATT服务和特性,在其中一些上启用通知,并读/写其中一些。

Mar*_*sek 6

这个问题的答案很简单-不要在Windows 10上使用BLE。该API无法正常工作或行为随机,并且完全没有文档说明。我喜欢每个人都在谈论物联网是下一次工业革命,并且微软在存在6年的BLE后仍无法使用BLE API。

  • 自 2017 年 3 月起,创作者更新使 API 得到了显着改进。 https://learn.microsoft.com/en-us/windows/uwp/devices-sensors/bluetooth-low-energy-overview (2认同)