giomurru / ble-framework

A Unity framework for using bluetooth low energy (BLE) ReadBearLab boards with iOS and Android mobile platforms.
MIT License
83 stars 23 forks source link

How to send data from Unity to Android (via BLE) #1

Closed PedroLopes closed 6 years ago

PedroLopes commented 8 years ago

Everything works, i.e., I can connect the phone (running your code in Unity, on an android) and my arduino which has a BT LE module. (I see the blue LED that signifies the connection worked).

However, the function _SendData, crashes in runtime with: 07-10 18:38:28.493 4294-4318/? I/Unity: AndroidJavaException: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattCharacteristic.setValue(byte[])' on a null object reference java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattCharacteristic.setValue(byte[])' on a null object reference at com.gmurru.bleframework.BleFramework._SendData(BleFramework.java:605) at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.a(Unknown Source) at com.unity3d.player.UnityPlayer$b.run(Unknown Source) at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0 at UnityEngine.AndroidJNISafe.CallVoidMethod (IntPtr obj, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0 at UnityEngine.AndroidJavaObject._Call (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0 at UnityEngine.AndroidJavaObject.Call (System.String methodName, System.O

Is this the proper way to send a few bytes through the BT connection? Do I have to initialize a service first? (I do that in my Android Studio app, was trying to replicate in Unity)

giomurru commented 8 years ago

Hi Pedro, I can't test it right now because I recently changed place where I live and I don't have the ble mini and arduino with me. I see that my latest commit on the project says "Everything works on Android except the fact that data is not transmitted correctly". I am sorry to say, I wasn't able to solve the problem because by knowledge of Android architecture is limited compared to the one of iOS I have. If you are able to solve the problem you are welcome to submit a pull request in github, please.

Thank you for your time,

Giovanni

On Sun, Jul 10, 2016 at 6:45 PM, Pedro Lopes notifications@github.com wrote:

Everything works, i.e., I can connect the phone (running your code in Unity, on an android) and my arduino which has a BT LE module. (I see the blue LED that signifies the connection worked).

However, the function _SendData, crashes in runtime with: 07-10 18:38:28.493 4294-4318/? I/Unity: AndroidJavaException: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattCharacteristic.setValue(byte[])' on a null object reference java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattCharacteristic.setValue(byte[])' on a null object reference at com.gmurru.bleframework.BleFramework._SendData(BleFramework.java:605) at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.a(Unknown Source) at com.unity3d.player.UnityPlayer$b.run(Unknown Source) at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0 at UnityEngine.AndroidJNISafe.CallVoidMethod (IntPtr obj, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in :0 at UnityEngine.AndroidJavaObject._Call (System.String methodName, System.Object[] args) [0x00000] in :0 at UnityEngine.AndroidJavaObject.Call (System.String methodName, System.O

Is this the proper way to send a few bytes through the BT connection? Do I have to initialize a service first? (I do that in my Android Studio app, was trying to replicate in Unity)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/giomurru/ble-framework/issues/1, or mute the thread https://github.com/notifications/unsubscribe/ACr6QC7RAFCrH-JYTBUVwJfftZrVoFPMks5qUSG3gaJpZM4JI3sa .

varunvp commented 7 years ago

Is this issue solved as of now?

hanfengsunshine commented 7 years ago

Is this issue solved ? It wouldn.t work right now?

akainth commented 7 years ago

Please note that the issue was because of wrong UUID in .jar file. My android developer friend changed the UUID in .jar file and it is working fine now.

Apart from .jar file, great plugin. Thanks Giovanni!

BleFrameworkPlugin.jar.zip

giomurru commented 7 years ago

@akainth can you please explain how did you solve the problem in the code that generates the jar? What UUID did you change? Thank you.

giomurru commented 7 years ago

I'm working on the problem on the branch android-fix-dev. I switched to Android Studio build, so please ignore the instructions about ant. Furthermore Unity project already include the compiled jar android plugin and is ready to use. Unfortunately not everything is working. You are welcome to contribute in the Android Plugin Project if you have any fix.

akmaaak commented 6 years ago

Is there anybody who could solve the issue? I am having the same issue now. I need help about this problem

kartik9k commented 6 years ago

Yes please, I'm stuck on the same issue as well, with android!

Vinh-Beo commented 5 years ago

Is there any people who could solve this issue already? Please help me!!!!:((