蓝牙LEAdvertisementWatcher Hololens 上没有活动

问题描述

我正在尝试通过 BLE 广告将 GPS 坐标从 Android 设备发送到 Hololens。 就我所见,问题是来自 bluetoothleadvertisementwatcher 的事件不会在 Hololens 上触发。

我试过复制粘贴这两个implementationthis 在接收方,没有收到事件。

这是 Unity 中的当前实现,我在一个空白的 UWP-C# 项目中实现了相同的功能,并直接部署在 Hololens 上,结果相同。

ask

我知道广告已发送,因为如果我直接在 PC 上的 Visual Studio 中调试本机 UWP 应用程序(即使是 ARM64),一切正常。事件被触发。 private void StartWatcher() { void OnAdvertisementReceived(object sender,BluetoothLEAdvertisementReceivedEventArgs eventArgs) { Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation } void OnAdvertisementStop(object sender,bluetoothleadvertisementwatcherStoppedEventArgs eventArgs) { Debug.Log("Event triggered"); // switched to Write-line on the C#->UWP implementation } try { bluetoothleadvertisementwatcher watcher = new bluetoothleadvertisementwatcher(); watcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(GetManufacturerData()); watcher.Received += OnAdvertisementReceived; watcher.Stopped += OnAdvertisementStop; watcher.Start(); Debeug.Log("Started"); // switched to Write-line on the C#->UWP implementation } catch (Exception e){ } } private BluetoothLEManufacturerData GetManufacturerData() { var manufacturerData = new BluetoothLEManufacturerData(); manufacturerData.CompanyId = 0X06EF; return manufacturerData; 报告在 Hololens 上“开始” 即使我在应用程序运行时禁用 HoloLens 上的蓝牙,也不会触发停止事件。 如果我在禁用蓝牙后检查 watcher.Status,状态报告已中止,但未收到停止事件。

功能在此article

之后被激活

现在到了奇怪的地方。 在我的第一次尝试中,我的应用程序在 Hololens 上运行,因为我试图删除 Android 设备和 HoloLens 之间的配对。 android 设备在 Hololens 上显示为两个设备,设备名称一个,“LE”+MAC 为另一个。 在我使用蓝牙设置并从手机上取下两个适配器期间的某个时候,HoloLens 收到了三个单独的广告。广告中的数据也从我的 Android 设备中得到了确认,因为在我最初尝试时,我解析了数据。

但就是这样,我今天尝试将其复制 10 个小时,在不同阶段配对和取消配对不同的适配器,同时侦听接收事件但没有运气。 在我的 PC 上,适配器是否配对并不重要。

我已经尝试了 .NET Standard 2.0 和 .Net 4.x 作为 API 兼容级别。 我在接收和停止事件处理程序中都设置了断点,因为我担心来自事件函数调用是问题所在。据我所知,我们从未达到已实施的事件。

对下一步检查的任何建议表示赞赏。

Hololens 版本是 19041.1144。

解决方法

好的,现在我可以通过运行 Microsoft 证明的示例来接收 HoloLens 上的广告。 我根本无法接收任何事件,并且设置中没有可用更新,所以我重新安装了 Microsoft Store 中的所有应用程序,这似乎是我的解决方案。在那之后,重新启动 HoloLens,我能够从我的 PC 接收广告。

对于试图在 HoloLens 2 上接收广告的人们的另一个提示。 当我能够从我的电脑接收广告时,我看到来自我的 Android 设备的广告没有在 HoloLens 上接收,而是在 PC 上接收。 我 PC 上的广告类型为 NonConnectableUndirected,来自我的 Android 设备 ScannableUndirected。 我需要更改为“AdvertisingSet”并在 AdvertisingSetParameters 中将 isConnectable 和 isScannable 设置为 false 才能发送 NonConnectableUndirected。 现在 HoloLens 可以从我的 Android 设备接收广告。