简体   繁体   English

如何在 Unity3D HoloLens 应用程序上检测 BLE 信标?

[英]How to detect BLE beacons on Unity3D HoloLens app?

I have built an app in Unity3D which should be able to detect Bluetooth Low-Energy beacons on the Microsoft HoloLens.我在 Unity3D 中构建了一个应用程序,它应该能够检测 Microsoft HoloLens 上的蓝牙低功耗信标。 Here is the Unity C# script code that I used to get this done.这是我用来完成此任务的 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!");
    }

}

The app builds and runs on the HoloLens nicely, but (even after waiting a couple of minutes) I do not get the desired output line in my debug log.该应用程序可以很好地在 HoloLens 上构建和运行,但是(即使等待几分钟后)我的调试日志中也没有得到所需的输出行。 This means to me that the WatcherOnReceived() method is never called, which ultimately means that no beacon is detected .这对我来说意味着WatcherOnReceived()方法永远不会被调用,这最终意味着没有检测到信标

I use some Sensoro SmartBeacon-4AA 's which can transmit both iBeacon and Eddystone signals.我使用了一些Sensoro SmartBeacon-4AA可以传输 iBeacon 和 Eddystone 信号。

I have been trying this for a couple of weeks right now, did several tutorials along the way but I still can not figure out why this is not working for me.我已经尝试了几个星期,一路上做了几个教程,但我仍然不明白为什么这对我不起作用。

It was a permission problem after all.毕竟是权限问题。 It is possible to solve this issue in both Unity (pre-build) and Visual Studio (post-build).可以在 Unity(预构建)和 Visual Studio(构建后)中解决此问题。 Here are both solutions:以下是两种解决方案:

Solution A: in Unity解决方案 A:在 Unity 中

  1. Head to Edit > Project Settings > Player .前往Edit > Project Settings > Player
  2. In the Inspector , open up the tab Publishing Settings .Inspector 中,打开标签Publishing Settings
  3. Under the Capabilities section, make sure that Bluetooth is enabled .功能部分下,确保蓝牙已启用

在此处输入图片说明 Click on the .gif to expand单击 .gif 以展开

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

  1. In your Solution Explorer (Ctrl+Alt+L), expand your project.在您的解决方案资源管理器(Ctrl+Alt+L) 中,展开您的项目。
  2. Double-click the Package.appxmanifest .双击Package.appxmanifest
  3. Go to the Capabilities tab.转到功能选项卡。
  4. Again, make sure that Bluetooth is enabled .再次确保蓝牙已启用

在此处输入图片说明 Click on the .gif to expand单击 .gif 以展开

This will give your app the right to use Bluetooth on the HoloLens.这将使你的应用有权在 HoloLens 上使用蓝牙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM