Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality. If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers. And always feel free to hit us up on Twitter @MxdRealityDev.

Hololens and Beacons

I was wondering if anyone had tried to use beacons with the Hololens ? I can't seem to find a definitive answer as to whether it will work or not . Thanks .

Best Answer

  • MattFedoCSGMattFedoCSG ✭✭
    Accepted Answer

    Ok so here is the breakdown.

    1) Find and download the .NET 4 Windows.Devices.Bluetooth DLL
    2) In Unity, create the Assets > Plugins > WSA folder and place that DLL in it. When you check the import settings of this DLL, it can be set to 'Any Platform' and it will say 'Native' as the Type, which is fine.
    3) Next, add the DLL I attached to this comment to the Assets > Plugins folder. When you check the import settings of this DLL, you can check it just for WSAPlayer, SDK = UWP, Scripting = Dot Net, and you will see it Managed as a 4.x assembly.
    4) So lets look at some code on the Unity side now. Everything you do to "reference" the DLL, you are going to need to wrap in #if !UNITY_EDITOR because you dont want it to compile.

    #if !UNITY_EDITOR
    using HoloBeaconScanner;
    #endif
    

    Next under Start() on your script we can place:

    #if !UNITY_EDITOR
            Scanner beaconScanner = new Scanner();
            Scanner.ScannedBeaconEventHandler += BeaconFound;
            beaconScanner.StartScanning();
    #endif
    

    There is also a .StopScanning() function if you make your var global.

    And once you are scanning you can just set the even handler to catch that Beacon info:

     public void BeaconFound(string str)
        {
            try
            {
                char[] delimiterChars = { '*' };
                string[] components = str.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
                if (components[1] != "0")
                {
                    Debug.Log("[BEACON DETECTOR] : FOUND : " + str.ToString());
                }
            }
            catch(Exception ex)
            {
                //Log error or something else.
            }
        }
    

    So the beacon data comes back as a delimited string. I will update it with a JSON package, but right now it is delimited by a *.

    Components are as follows:
    0 = UUID
    1 = Major
    2 = Minor
    3 = TxPower
    4 = Raw Signal Strength in DBm

    If the Holo does not find a beacon or encounters an error, it will return:

    0000000-0000-0000-0000-0000000000000000

    So keep that in mind, and hence why I check for Component 1 to be 0 and ignore it.

    I hope this helps someone out there and hope it keeps advancing the Hololens Experience! I will try to keep the DLL up to date! Thanks!

Answers

  • @Hannah
    Have you find any solutions?

  • No not yet . I may look into buying some and trying them out . @Ankit09_Sangani

  • @Hannah
    Thanks for quick response.
    have you try this
    https://github.com/andijakl/universal-beacon
    I tried but always Beacon List Count 0 :(

  • @Ankit09_Sangani hi - that repository is for UWP only. Did you create a stub for the DLL for Unity editor ?

  • You should be able to set the import settings on the DLL to Windows and then set don't compile. You will be able to access the Dll that way. I will give it a go today and see what happens. Holo is UWP btw.

  • I got it working. DLLs coming.

  • MattFedoCSGMattFedoCSG ✭✭
    Accepted Answer

    Ok so here is the breakdown.

    1) Find and download the .NET 4 Windows.Devices.Bluetooth DLL
    2) In Unity, create the Assets > Plugins > WSA folder and place that DLL in it. When you check the import settings of this DLL, it can be set to 'Any Platform' and it will say 'Native' as the Type, which is fine.
    3) Next, add the DLL I attached to this comment to the Assets > Plugins folder. When you check the import settings of this DLL, you can check it just for WSAPlayer, SDK = UWP, Scripting = Dot Net, and you will see it Managed as a 4.x assembly.
    4) So lets look at some code on the Unity side now. Everything you do to "reference" the DLL, you are going to need to wrap in #if !UNITY_EDITOR because you dont want it to compile.

    #if !UNITY_EDITOR
    using HoloBeaconScanner;
    #endif
    

    Next under Start() on your script we can place:

    #if !UNITY_EDITOR
            Scanner beaconScanner = new Scanner();
            Scanner.ScannedBeaconEventHandler += BeaconFound;
            beaconScanner.StartScanning();
    #endif
    

    There is also a .StopScanning() function if you make your var global.

    And once you are scanning you can just set the even handler to catch that Beacon info:

     public void BeaconFound(string str)
        {
            try
            {
                char[] delimiterChars = { '*' };
                string[] components = str.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
                if (components[1] != "0")
                {
                    Debug.Log("[BEACON DETECTOR] : FOUND : " + str.ToString());
                }
            }
            catch(Exception ex)
            {
                //Log error or something else.
            }
        }
    

    So the beacon data comes back as a delimited string. I will update it with a JSON package, but right now it is delimited by a *.

    Components are as follows:
    0 = UUID
    1 = Major
    2 = Minor
    3 = TxPower
    4 = Raw Signal Strength in DBm

    If the Holo does not find a beacon or encounters an error, it will return:

    0000000-0000-0000-0000-0000000000000000

    So keep that in mind, and hence why I check for Component 1 to be 0 and ignore it.

    I hope this helps someone out there and hope it keeps advancing the Hololens Experience! I will try to keep the DLL up to date! Thanks!

  • @MattFedoCSG said:
    Ok so here is the breakdown.

    1) Find and download the .NET 4 Windows.Devices.Bluetooth DLL
    2) In Unity, create the Assets > Plugins > WSA folder and place that DLL in it. When you check the import settings of this DLL, it can be set to 'Any Platform' and it will say 'Native' as the Type, which is fine.
    3) Next, add the DLL I attached to this comment to the Assets > Plugins folder. When you check the import settings of this DLL, you can check it just for WSAPlayer, SDK = UWP, Scripting = Dot Net, and you will see it Managed as a 4.x assembly.
    4) So lets look at some code on the Unity side now. Everything you do to "reference" the DLL, you are going to need to wrap in #if !UNITY_EDITOR because you dont want it to compile.

    #if !UNITY_EDITOR
    using HoloBeaconScanner;
    #endif
    

    Next under Start() on your script we can place:

    #if !UNITY_EDITOR
            Scanner beaconScanner = new Scanner();
            Scanner.ScannedBeaconEventHandler += BeaconFound;
            beaconScanner.StartScanning();
    #endif
    

    There is also a .StopScanning() function if you make your var global.

    And once you are scanning you can just set the even handler to catch that Beacon info:

     public void BeaconFound(string str)
        {
            try
            {
                char[] delimiterChars = { '*' };
                string[] components = str.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
                if (components[1] != "0")
                {
                    Debug.Log("[BEACON DETECTOR] : FOUND : " + str.ToString());
                }
            }
            catch(Exception ex)
            {
                //Log error or something else.
            }
        }
    

    So the beacon data comes back as a delimited string. I will update it with a JSON package, but right now it is delimited by a *.

    Components are as follows:
    0 = UUID
    1 = Major
    2 = Minor
    3 = TxPower
    4 = Raw Signal Strength in DBm

    If the Holo does not find a beacon or encounters an error, it will return:

    0000000-0000-0000-0000-0000000000000000

    So keep that in mind, and hence why I check for Component 1 to be 0 and ignore it.

    I hope this helps someone out there and hope it keeps advancing the Hololens Experience! I will try to keep the DLL up to date! Thanks!

    Thanks !! I cant wait to try this out !

  • Hello!
    Where can I find the Windows.Devices.Bluetooth Dll?

    Thanks.

  • kartikkartik
    edited July 16

    @MattFedoCSG I tried it but still not working with hololens 1. Can you please share the code or unity project, I urgently need it for my project.

Sign In or Register to comment.