robalem
robalem

Reputation: 169

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. Here is the Unity C# script code that I used to get this done.

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. This means to me that the WatcherOnReceived() method is never called, which ultimately means that no beacon is detected.

I use some Sensoro SmartBeacon-4AA's which can transmit both iBeacon and Eddystone signals.

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.

Upvotes: 1

Views: 3017

Answers (1)

robalem
robalem

Reputation: 169

It was a permission problem after all. It is possible to solve this issue in both Unity (pre-build) and Visual Studio (post-build). Here are both solutions:

Solution A: in Unity

  1. Head to Edit > Project Settings > Player.
  2. In the Inspector, open up the tab Publishing Settings.
  3. Under the Capabilities section, make sure that Bluetooth is enabled.

enter image description here Click on the .gif to expand

Solution B: in Visual Studio (2017)

  1. In your Solution Explorer (Ctrl+Alt+L), expand your project.
  2. Double-click the Package.appxmanifest.
  3. Go to the Capabilities tab.
  4. Again, make sure that Bluetooth is enabled.

enter image description here Click on the .gif to expand

This will give your app the right to use Bluetooth on the HoloLens.

Upvotes: 3

Related Questions