无头 UWP 蓝牙配对,无需用户 PIN 输入



我目前正在构建一个在Windows 10 IoT Core上运行的无头UWP应用程序。 我需要能够通过蓝牙 (RFCOMM( 将移动设备连接到信息亭以收集数据。 我需要能够从移动设备启动配对。

我已经试验了所有 UWP 蓝牙示例应用,但主要试验了设备枚举和配对 C# 示例- 特别是方案 9 - 自定义设备配对。 我可以使用引脚成功配对到有头的 UWP 应用,但无法成功配对到我的无外设 UWP 应用 - 尝试启动配对时出现"失败"结果或"身份验证超时"结果。

如何在没有 UI 的情况下与无头 UWP 应用配对以检索引脚? 我可以接受 UWP 应用程序,每次配对尝试都有一个硬编码引脚而不是随机引脚,但我不确定这是否可能?

您可以尝试使用以下代码。当有传入的配对请求时,将调用处理程序更新程序。

handlerUpdated = new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>(async (watcher, deviceInfoUpdate) =>
{
// Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
await MainPage.Current.UIThreadDispatcher.RunAsync(CoreDispatcherPriority.Low, async () =>
{
// Find the corresponding updated DeviceInformation in the collection and pass the update object
// to the Update method of the existing DeviceInformation. This automatically updates the object
// for us.
foreach (BluetoothDeviceInformationDisplay deviceInfoDisp in bluetoothDeviceObservableCollection)
{
if (deviceInfoDisp.Id == deviceInfoUpdate.Id)
{
if (deviceInfoDisp.DeviceInformation.Pairing.CanPair)
{
await deviceInfoDisp.DeviceInformation.Pairing.Custom.PairAsync(DevicePairingKinds.ConfirmOnly);
}
deviceInfoDisp.Update(deviceInfoUpdate);
break;
}
}
});
});
deviceWatcher.Updated += handlerUpdated;

最新更新