I am trying to interface a smartphone to a BLE server using the BLE2 library.
After a confusing start, I am now able to connect, discover etc. I am able to send data (it was very easy) and receive data (less easy).
The problem is that I don't want to poll the device, I want to be notified when the data (characteristic) varies.
So, I try to use SetNotify() after connecting:
When calling SetNotify() the following exception is reported in the log:
Error occurred on line: 87 (B4XMainPage)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.BleManager2.setNotify(BleManager2.java:355)
at anywheresoftware.b4a.objects.BleManager2.SetNotify(BleManager2.java:344)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
I can not understand what I am missing here. the UUIDS for service and characteristics are correct, in fact I can send and receive.
Is there something else to do before using SetNotify()? I tried also to invoke it in the DataAvailable event handler, but the result is the same.
After a confusing start, I am now able to connect, discover etc. I am able to send data (it was very easy) and receive data (less easy).
The problem is that I don't want to poll the device, I want to be notified when the data (characteristic) varies.
So, I try to use SetNotify() after connecting:
B4X:
Sub theble_Connected (services As List)
Log("Connected")
For Each st As String In services
Log(" service " & st)
If st="96ded887-592d-48e1-9fe4-903046afff16" Then
' theble.ReadData2(st, "bb7b236e-eeef-42c5-ab0d-3305051c5c49")
End If
Next
theble.SetNotify("96ded887-592d-48e1-9fe4-903046afff16", "bb7b236e-eeef-42c5-ab0d-3305051c5c49", True)
End Sub
When calling SetNotify() the following exception is reported in the log:
Error occurred on line: 87 (B4XMainPage)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.BleManager2.setNotify(BleManager2.java:355)
at anywheresoftware.b4a.objects.BleManager2.SetNotify(BleManager2.java:344)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
I can not understand what I am missing here. the UUIDS for service and characteristics are correct, in fact I can send and receive.
Is there something else to do before using SetNotify()? I tried also to invoke it in the DataAvailable event handler, but the result is the same.