1
votes

I have a game programmed in Unity3D in order to publish it in the end to iOS and Android.

Suppose the game App is installed on the mobile and I want to control it through an external Bluetooth Low energy device (for example - Heart rate sensor)
What would be the better way to make the architecture for that for making it cross platform?
For example - to make it the easiest way to implement it on iOS and Android as well?

    *External*        *Mobile* 

Bluetooth Low Energy device --> Something.. --> Unity

Something = What cross platform framework do you advice me to use that can interface with the Bluetooth Low Energy (in the future also with Database) and the Unity3D to pass it the logic ?

Thanks a lot

1

1 Answers

4
votes

Unity does NOT have a Bluetooth API to use bluetooth on iOS and Android. The way to do this to make a plugin.

For iOS, you can write a plugin or functions in Ocjective-C or C++. You then place the .cpp or.mm file in your Assets/Plugins/iOS directory.

For Android, You have to write the Android plugin in Java or C++ then compile it into .jar exntention and place the jar file in Assets/Plugins/Android

Each plugin should have thesame function names so that they will be compatible with each other. When you want to compile for Android or iOS, Unity will automatically choose the correct plugin folder to use for the specified mobile platform.

The good way of making this plugin is to write a whole Application in iOS or Android and test your functions in XCode or Android Studio. If they work, then you can go ahead and convert it to plugin to be used in Unity. This saves time.

EDIT:

I don't like adversing products but I know this will help you so here is a plugin that you can use for Bluetooth LE communcaitions that works on Android and iOS. https://www.assetstore.unity3d.com/en/#!/content/26661 This plugin is new but ihas good reviews. That's why I posted it.

Please bear in mind that most Heart rate sensors come with a built in security and proprietary communication protocol. So, even if it uses Bluetooth, you will have to reverse engineer the protocol and then write a c# class using the Bluetooth plugin I linked here to be able to communicate with them. You can reverse engineer any Heart rate sensor. Just buy one of the famous ones then get an iPhone and Android phone.

Jailbreak the iPhone and root the Android device. Install bluetooth sniffing app and try to communicate your Heart rate sensor device with the with either iPhone or Android. You can read what is been sent to the Heart rate sensor device from the iPhone/Android or what iPhone/Android is sending to the Heart rate sensor device. That is what you need to be sending to it in your c# class to make it work. Other ways of doing this is de-compiling the app that comes with the Heart rate sensor device(Not recommended). You can see what's going on from there.

If the Heart rate sensor has an API for android or iOS, you will then have no other option but to write the plugin yourself on top of the API they provided for it.

If you are making your own Heart rate sensor device, then that should be easier. You can make a prototype with Arduino and communicate to it with the Plugin I linked here. If it works, you can then move on to make it a real product.

It looks like the H6 and H7 are the most famous ones. They also have a developer page. It hould be easy to communicate with these because they use standard protocol instead of proprietary ones just like some do.

http://developer.polar.com/wiki/H6_and_H7_Heart_rate_sensors

Android heart rate sensor code(standard):

http://developer.android.com/guide/topics/connectivity/bluetooth-le.html

iOS heart rate sensor code(not about standard):

http://developer.polar.com/wiki/H6_and_H7_Heart_rate_sensors#HR_example_code_for_Android

You can email the developer of the plugin I posted in link and ask they could support or help you implement heart rate sensor. They might even do it. Good luck.