Search Unity

bluetooth low energy on windows under unity

Discussion in 'Windows' started by titof49, Dec 19, 2017.

  1. titof49

    titof49

    Joined:
    Dec 19, 2017
    Posts:
    9
    Hi,

    I'm working on a project using Bluetooth low energy on uwp application.

    I already worked with visual studio to obtain orientation of the thingy (nordic semi conductor) but i would now integrate it to unity.

    the main issue is that i cannot use

    using Windows.Devices.Bluetooth;
    using Windows.Devices.Bluetooth.GenericAttributeProfile;

    when i had them, unity doesn't want compilate.

    may i create a c# dll for my functions using visual studio and after integrate it to my project or is it possible to add the "Windows.Devices.Bluetooth.dll" Library to add support to mono ?

    already thanks for your reponses.

    Br,
    Christophe
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,443
    You can use these namespaces if you wrap you code in #if ENABLE_WINMD_SUPPORT/#endif. Note that the code will only be compatible with UWP player, and will not execute in the editor.
     
  3. titof49

    titof49

    Joined:
    Dec 19, 2017
    Posts:
    9
    ok, i'll test. thank you for your quick response
     
  4. vrobel

    vrobel

    Joined:
    Dec 29, 2016
    Posts:
    1
    I wanted to connect our VR game (Steam VR or Oculus) with our custom Bluetooth LE controller. Any ideas how to use Windows SDK not on UWP platform? Native plugin for Win made in C++? If it's not possible I'll try to make it as a separate UWP app that connects via Socket.
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,443
    Yeah you'll have to use C++ in a native plugin.
     
  6. titof49

    titof49

    Joined:
    Dec 19, 2017
    Posts:
    9
    yes, i agree with you, we need a c++ plugin.

    i take the project on
    https://bitbucket.org/Unity-Technologies/windowsstoreappssamples

    and i updated the two projects:

    for the first one is used :

    #include <windows.h>
    #include <stdio.h>
    #include <setupapi.h>
    #include <devguid.h>
    #include <regstr.h>
    #include <bthdef.h>
    #include <bthledef.h>
    #include <Bluetoothleapis.h>
    #pragma comment(lib, "SetupAPI")
    #pragma comment(lib, "BluetoothApis.lib")​

    in the stdafx.h file and i based the projest on :

    https://social.msdn.microsoft.com/F...-c-for-bluetooth-low-energy-devices?forum=wdk

    i added the function in stdafx.cpp to verify the compilation:

    void SomethingHappened(BTH_LE_GATT_EVENT_TYPE EventType, PVOID EventOutParameter, PVOID Context)

    for the second project (wsa plugins) t was more difficult because winrt wasn't unable to compilate, i found the soultion as this:

    in stdafx.h

    // Windows Header Files:
    #pragma comment(lib, "windowsapp")
    #include "Windows.Foundation.h"
    #include "Windows.Web.Syndication.h"
    #include "Windows.devices.bluetooth.h"
    #include "Windows.devices.bluetooth.background.h"
    #include "Windows.devices.bluetooth.advertisement.h"​

    and in the stdafx.cpp



    #include "stdafx.h"
    using namespace std;
    using namespace Windows;
    using namespace Windows::Devices;
    using namespace Windows::Devices::Bluetooth;
    using namespace Windows::Devices::Bluetooth::Background;
    using namespace Windows::Devices::Bluetooth::Advertisement;
    using namespace Windows::Devices::Bluetooth::GenericAttributeProfile;​

    but to conclude the conpilation, you need to change the project as this:

    use Windows extension runtime in the project properties Under C/C++ and General Yes(/ZW)

    after you can compilate the basic dll standlone dll and the wsa with winrt plugin

    it's for the c++ part.

    i'll check for the c# dll plugin possibility a i already did the code for the wesu (st micro electronics) and the thingy from nordic.
     

    Attached Files:

  7. titof49

    titof49

    Joined:
    Dec 19, 2017
    Posts:
    9
    To Tautvydas-Zilys:

    don't hesitate to comment to see if it feels right for you.

    Br,
    could be the basics to implement it in the next version of unity ;->
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,443
    I don't think we have plans to add bluetooth functionality to Unity at this time...
     
  9. titof49

    titof49

    Joined:
    Dec 19, 2017
    Posts:
    9
    ok, no problem.

    I'll check the third case to cover my project: une a c# dll to support the Bluetooth.

    in this case 3 possibility:
    c++ dll for stand alone project.
    c++ dll with was for Windows store.
    dedicated dll compose in a version 'fake' for the editor with the mono framwork and one with the winrt Framework to be able to run.

    but the ++ dll feels to be the best way.

    Br,
    Christophe.

    Remark: we see Bluetooth packages for ios and android but not uwp/Windows standalone.
    so i think it can be a good idea for the asset market.
     
  10. titof49

    titof49

    Joined:
    Dec 19, 2017
    Posts:
    9
    Ok, the stand Alone plugin work.
    I ll create a generic version of the stand alone plugin.
    I m working now
    on the uwp version
    Already Nordic semi / stmicro compliant.
    I plan to do the same thing with Philips nxp kinetics version
     
  11. bluetenu

    bluetenu

    Joined:
    Dec 6, 2014
    Posts:
    5
    @titof49 Just curious when your bluetooth standalone and/or uwp asset might be available in the Unity store or elsewhere?
     
  12. erzshalom

    erzshalom

    Joined:
    Jun 13, 2018
    Posts:
    3
    @titof49 Can you please update with the result? we have the same problem and curious if you can share your solution
    Thanks!
     
  13. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    215
    I am newbie in Unity3d.I checked for a bluetooth plugin for unity and i found out that in-order to use plugin we need to know Java for android and Swift for IOS.I dont know these two languages.All I know is Csharp and unity.Is there anyway I could learn how to make a plugin.Any tutorials?
     
  14. qoobit

    qoobit

    Joined:
    Aug 19, 2014
    Posts:
    40
    Hotshot10101 likes this.
  15. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    215
    @qoobit I got this plugin...but the problem is how to show indoor navigation using beacons...It is tough to show which direction the beacons are placed...You can get the RSSI values(range of beacon).How to show a path?I got no clue.
     
  16. qoobit

    qoobit

    Joined:
    Aug 19, 2014
    Posts:
    40
    If you have the RSSI I think you can use triangulation principles if you have two or more devices. https://en.m.wikipedia.org/wiki/Triangulation_(surveying)
    You would effectively measure out the RSSI falloff graph for each of your beacons and based on values of each you can estimate which ring they are in for each beacon. Overlapping points will determine where they roughly are in the space. In certain scenarios you will have two overlaps so you usually require an additional device in range to eliminate the possibilities.
     
    Hotshot10101 likes this.
  17. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    215
    @qoobit Thanks will look into that...Recently saw a video about indoor navigation without using beacons.So was looking to do that as beacons are getting outdated.Currently researching how to do it without using beacons.
     
  18. xmedeko

    xmedeko

    Joined:
    Jun 6, 2018
    Posts:
    23