MetaWear Game App on Unity - Guide for BLE

Hello,
I'm looking into attempting to make a 3D game that makes use of MetaMotion R sensors (acceleration & gyroscope) as the user input. I'm considering using Unity for Windows for the development, but if needed, I could go for other alternatives.

Currently, I'm not sure how I should go about writing the Bluetooth LE (BLE) Communication codes, is there any reference for it (be it C# or C++)?
Furthermore, Unity uses C#, but does not have direct access to WinRT API, thus would not be able to call into GATT operations easily. Should I be writing the BLE codes as a C#/C++ library, then export the DLL to Unity, or write them in Unity directly?

Any help or tips on how I should proceed would be appreciated!

Comments

  • Some users in this thread have successfully made console apps that call into the WinRT API using C#.

    You can reuse the Bluetooth code from the UWP template app:
  • Thanks Eric!

    I've actually started with trying out the UWP Starter template, just to understand how everything works first.

    I'm having an issue with the template (currently only running the build from Visual Studio so far), where upon starting the application, although my device is detected, if I click on it, it'll fail to initialize the API due to timeout (however, it's already at 4 seconds and increasing it doesn't help). The address text is in red as well, which if I understand this correctly, means the device is not connected.
    Only if I refreshed once (or sometimes multiple times) will I be able to connect successfully.
    If I failed to initialize the API, when I run the application again, the address will sometimes be in green, and in these cases I can connect immediately without needing to refresh.

    I've noticed I also have this issue with initializing the API when using the MetaBase app from the Windows Store.

    Was something missed out in initializing the BLE when starting the application, or is this an issue with my computer/Bluetooth connection?
  • This appears to be an issue with your Bluetooth adapter, driver, or OS; setting the time for response to 4s should be plenty of time to go through the initialization process.

    If you are up for further debugging, log the values of the writeCharacteristic function along with a timestamp at line of code in the starter template.
  • Hello again,

    Thanks for the suggestion, I've tried out on another win10 laptop.
    The problem seems to be on and off for both computers; it works fine sometimes but at other times it'll crash again.
    Not sure if it's because I removed the sensor from my computer's Bluetooth connection, then reconnected it again, that solved the issue temporarily.
  • Hi Eric,

    The connection issue seems to be getting worse. I am unable to initiate a connection at all on most times now, and usually I have to soft reset and bring the sensor out of Bluetooth range from my devices before it can initiate a connection again.
    As of now, I can only make 1 successful connection before I have to reset the sensor.

    Is this a known issue? It may not be my laptop's Bluetooth driver that has an issue as when I first started testing the app, the connectivity  issue was not as bad as this.
  • edited July 2017
    Modify your app as outlined in my previous post and post the values logged in the console.  Also, please post the code you are currently running in your app.
This discussion has been closed.