Hi all,
I am starting with BLE, using a RN4020 module. At this moment, the module is connected with USB to the PC serial port. The final purpose is to stablish a communication channel with a microcontroller that will be behind the module.
I have read documentation and tried many examples here
What I have done (from a post here in the forum) on the module side :
I define a private service in the module,
Doing it, either using BleExtEx or BLE2 library, I can see the service and the Characteristics. Also, they can be read and written to. So it works ok.
The problem comes when I want to use notifications. Perhaps I have understood wrongly the purpose of these, but if I do, in any of the examples ( in this case using BLEExtEx)
I change the definition of the first Characteristic in the module
And tell the manager that I want to be notified
Then the code fails on the above line
I get a similar error if I use the BLE2 library/example and "Starter.Manager.setNotify.."
What am I missing? Is the problem on the RN4020 side, on the android side (or in me )?
I am starting with BLE, using a RN4020 module. At this moment, the module is connected with USB to the PC serial port. The final purpose is to stablish a communication channel with a microcontroller that will be behind the module.
I have read documentation and tried many examples here
What I have done (from a post here in the forum) on the module side :
I define a private service in the module,
B4X:
SS,00000001 Set User Defined Private Profile
SR,20000000 Module is peripheral, Auto Advertise
R,1 Reboot, to let the changes become effective
PS,11223344556677889900AABBCCDDEEFF //Set the UUID of the Private Service. You can use any 128 bit number.
PC,AA02030405060708090A0B0C0D0E0F,06,14 //Add the first Characteristic to the Private Service. UUID,
Properties READ and WRITE WITHOUT ANSWER , maximum data size 20. Note, that all values have to be typed as hex numbers.
PC,BB02030405060708090A0B0C0D0E0F,06,14 // Add the second
Doing it, either using BleExtEx or BLE2 library, I can see the service and the Characteristics. Also, they can be read and written to. So it works ok.
The problem comes when I want to use notifications. Perhaps I have understood wrongly the purpose of these, but if I do, in any of the examples ( in this case using BLEExtEx)
I change the definition of the first Characteristic in the module
B4X:
PC,AA02030405060708090A0B0C0D0E0F,16,14 //Change characteristic to be notifiable
B4X:
Manager.SetCharacteristicNotification(CharRead,True) 'CharRead is the read characteristic
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
at anywheresoftware.b4a.objects.BleManager.SetCharacteristicNotification(BleManager.java:266)
at b4a.terminal.main._ble_characteristicread(main.java:407)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
at anywheresoftware.b4a.objects.BleManager.SetCharacteristicNotification(BleManager.java:266)
at b4a.terminal.main._ble_characteristicread(main.java:407)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
I get a similar error if I use the BLE2 library/example and "Starter.Manager.setNotify.."
What am I missing? Is the problem on the RN4020 side, on the android side (or in me )?