【问题标题】:How to detect BLE beacons on Unity3D HoloLens app?如何在 Unity3D HoloLens 应用程序上检测 BLE 信标?
【发布时间】:2017-10-06 14:09:30
【问题描述】:

我在 Unity3D 中构建了一个应用程序,它应该能够检测 Microsoft HoloLens 上的蓝牙低能耗信标。这是我用来完成此任务的 Unity C# 脚本代码。

using UnityEngine;
using Windows.Devices.Bluetooth.Advertisement;

public class BeaconDetector : MonoBehaviour
{

    private BluetoothLEAdvertisementWatcher _watcher;

    void Start()
    {
        _watcher = new BluetoothLEAdvertisementWatcher();
        _watcher.Received += WatcherOnReceived;
        _watcher.Start();
    }

    //This method should be called when a beacon is detected
    void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
    {
        //Just a simple check if this method is even called
        Debug.Log("Beacon detected!");
    }

}

该应用程序可以很好地在 HoloLens 上构建和运行,但是(即使在等待几分钟后)我的调试日志中也没有得到所需的输出行。这对我来说意味着永远不会调用 WatcherOnReceived() 方法,这最终意味着没有检测到信标

我使用了一些 Sensoro SmartBeacon-4AA,它们可以同时传输 iBeacon 和 Eddystone 信号。

我已经尝试了几个星期了,一路上做了几个教程,但我仍然不明白为什么这对我不起作用。

【问题讨论】:

  • 您是否已经尝试运行this sample app(Matt Fedorovich 的第二篇文章)?
  • 是的,和我提到的教程基本一样,只是写的有点不同
  • 所以该应用程序按预期工作还是不工作?因为如果不是,您可能有硬件故障或权限问题?
  • 嘿,我是 Matt,您应该使用的 DLL 的作者。使用本机 Windows 设备库将无法在 Unity 中用于构建它所需的 Unity 版本。您应该/可以使用我的 HoloBeaconScanner DLL 并使用 Scanner 类。我为你构建了所有的检测和解析。只需按照任一博客文章中的步骤操作,您就可以开始了。同样,无需引用 Windows 设备库,我已经为您完成了。

标签: c# unity3d bluetooth-lowenergy beacon hololens


【解决方案1】:

毕竟是权限问题。在 Unity(预构建)和 Visual Studio(构建后)中都可以解决此问题。以下是两种解决方案:

解决方案 A:在 Unity 中

  1. 前往编辑>项目设置>播放器
  2. Inspector中,打开标签Publishing Settings
  3. 功能部分下,确保蓝牙已启用

点击 .gif 展开

解决方案 B:在 Visual Studio (2017) 中

  1. 在您的解决方案资源管理器 (Ctrl+Alt+L) 中,展开您的项目。
  2. 双击Package.appxmanifest
  3. 转到功能标签。
  4. 再次确保蓝牙已启用

点击 .gif 展开

这将使您的应用有权在 HoloLens 上使用蓝牙。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    相关资源
    最近更新 更多