Android Question BLE2 - setNotify

kompiler

Member
Licensed User
Longtime User
I have problem with BLE2 library and Arduino Bluno form DFRoot
https://www.dfrobot.com/wiki/index.php/Bluno_SKU:DFR0267

DF Robot Service: 0000dfb0-0000-1000-8000-00805f9b34fb
DF Robot Characteristics: 0000dfb1-0000-1000-8000-00805f9b34fb

when I try SetIndication

B4X:
ServiceId = "0000dfb0-0000-1000-8000-00805f9b34fb"
ReadChar = "0000dfb1-0000-1000-8000-00805f9b34fb"

Private Sub Manager_Connected (Services As List)
    manager.SetIndication(ServiceId,ReadChar,True)
End Sub

in log

starter_manager_connected (java line: 144)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
at anywheresoftware.b4a.objects.BleManager2.setNotify(BleManager2.java:305)
at anywheresoftware.b4a.objects.BleManager2.SetNotify(BleManager2.java:295)
at b4a.example.starter._manager_connected(starter.java:144)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6126)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)


Bluno sends one character every second

Please help
 

kompiler

Member
Licensed User
Longtime User
I have v1.35. Services and characteristics in log

B4X:
Private Sub Manager_Connected (Services As List)
    For i=0 To Services.Size-1
        manager.ReadData(Services.Get(i))
    Next
End Sub

Private Sub Manager_DataAvailable (Srv As String, Characteristics As Map)
    Log(Srv)
    For i = 0 To Characteristics.Size - 1
        Log("Key: " & Characteristics.GetKeyAt(i))
        Log("Val: " & Characteristics.GetValueAt(i))
        Dim BC As ByteConverter
        Log("Str: " & BC.StringFromBytes(Characteristics.GetValueAt(i),"utf-8"))
    Next
    Log(" ")
End Sub

00001801-0000-1000-8000-00805f9b34fb
Key: 00002a05-0000-1000-8000-00805f9b34fb
Val: [B@ef3dba6
Str:

00001800-0000-1000-8000-00805f9b34fb
Key: 00002a00-0000-1000-8000-00805f9b34fb
Val: [B@32549e7
Str: BLUNO
Key: 00002a01-0000-1000-8000-00805f9b34fb
Val: [B@30f0994
Str: ����
Key: 00002a02-0000-1000-8000-00805f9b34fb
Val: [B@eca5c3d
Str: ��
Key: 00002a04-0000-1000-8000-00805f9b34fb
Val: [B@8720c32
Str: P����������
Key: 00002a03-0000-1000-8000-00805f9b34fb
Val: [B@8f29d83
Str:

0000180a-0000-1000-8000-00805f9b34fb
Key: 00002a23-0000-1000-8000-00805f9b34fb
Val: [B@19d2b00
Str: }��������
Key: 00002a24-0000-1000-8000-00805f9b34fb
Val: [B@5057f39
Str: DF Bluno
Key: 00002a25-0000-1000-8000-00805f9b34fb
Val: [B@f30b97e
Str: 0123456789
Key: 00002a26-0000-1000-8000-00805f9b34fb
Val: [B@5b78edf
Str: FW V1.93
Key: 00002a27-0000-1000-8000-00805f9b34fb
Val: [B@c29f72c
Str: HW V1.7
Key: 00002a28-0000-1000-8000-00805f9b34fb
Val: [B@f35d5f5
Str: SW V1.93
Key: 00002a29-0000-1000-8000-00805f9b34fb
Val: [B@19aef8a
Str: DFRobot
Key: 00002a2a-0000-1000-8000-00805f9b34fb
Val: [B@2b039fb
Str: ���experimental
Key: 00002a50-0000-1000-8000-00805f9b34fb
Val: [B@9d55a18
Str:
������

0000dfb0-0000-1000-8000-00805f9b34fb
Key: 0000dfb1-0000-1000-8000-00805f9b34fb
Val: [B@7dadc71
Str:
Key: 0000dfb2-0000-1000-8000-00805f9b34fb
Val: [B@7c07a56
Str:

Blue should be my characteristics and service

https://github.com/DFRobot/BlunoBasicDemo/blob/master/README.md
 
Upvote 0

kompiler

Member
Licensed User
Longtime User
Sending the character works well, I see in the console BLUNO incoming characters.

B4X:
manager.WriteData(ServiceId, ReadChar, BC.StringToBytes("test","utf-8"))

SetNotify still generates an error.

ServiceId = 0000dfb0-0000-1000-8000-00805f9b34fb
ReadChar = 0000dfb1-0000-1000-8000-00805f9b34fb

starter_manager_connected (java line: 145)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
at anywheresoftware.b4a.objects.BleManager2.setNotify(BleManager2.java:305)
at anywheresoftware.b4a.objects.BleManager2.SetNotify(BleManager2.java:295)
at b4a.example.starter._manager_connected(starter.java:145)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6126)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)


But if I change ServiceId and ReadChar, then there is no error

ServiceId = 00001801-0000-1000-8000-00805f9b34fb
ReadChar = 00002a05-0000-1000-8000-00805f9b34fb
without errors

ServiceId = 00001800-0000-1000-8000-00805f9b34fb
ReadChar = 00002a00-0000-1000-8000-00805f9b34fb
without errors

ServiceId = 0000180a-0000-1000-8000-00805f9b34fb
ReadChar = 00002a23-0000-1000-8000-00805f9b34fb
without errors
 
Upvote 0

kompiler

Member
Licensed User
Longtime User
Erel, thank you for your interest in the topic

B4X:
Private Sub Manager_Connected (Services As List)
    Log(manager.GetCharacteristicProperties(ServiceId, ReadChar))
End Sub

Log



I found more information about DFRobot BLE devices
https://www.dfrobot.com/forum/viewtopic.php?f=2&t=148
Can this information be useful?

attr handle: 0x0001, end grp handle: 0x000b uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x000c, end grp handle: 0x000f uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x0010, end grp handle: 0x0022 uuid: 0000180a-0000-1000-8000-00805f9b34fb
attr handle: 0x0023, end grp handle: 0xffff uuid: 0000dfb0-0000-1000-8000-00805f9b34fb

public static final String SerialPortUUID="0000dfb1-0000-1000-8000-00805f9b34fb";
public static final String CommandUUID="0000dfb2-0000-1000-8000-00805f9b34fb";
public static final String ModelNumberStringUUID="00002a24-0000-1000-8000-00805f9b34fb";

SerialPort String Notification Handle
char-read-uuid dfb1
handle: 0x0025 value: 3c

Command String
char-read-uuid dfb2
handle: 0x0028 value: 02

Model Number String
char-read-uuid 2a24
handle: 0x0014 value: 44 46 20 42 4c 75 6e 6f 00 == DF BLuno\0

> characteristics
handle: 0x0002, char properties: 0x02, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x0006, char properties: 0x0a, char value handle: 0x0007, uuid: 00002a02-0000-1000-8000-00805f9b34fb
handle: 0x0008, char properties: 0x0a, char value handle: 0x0009, uuid: 00002a03-0000-1000-8000-00805f9b34fb
handle: 0x000a, char properties: 0x02, char value handle: 0x000b, uuid: 00002a04-0000-1000-8000-00805f9b34fb
handle: 0x000d, char properties: 0x20, char value handle: 0x000e, uuid: 00002a05-0000-1000-8000-00805f9b34fb
handle: 0x0011, char properties: 0x02, char value handle: 0x0012, uuid: 00002a23-0000-1000-8000-00805f9b34fb
handle: 0x0013, char properties: 0x02, char value handle: 0x0014, uuid: 00002a24-0000-1000-8000-00805f9b34fb
handle: 0x0015, char properties: 0x02, char value handle: 0x0016, uuid: 00002a25-0000-1000-8000-00805f9b34fb
handle: 0x0017, char properties: 0x02, char value handle: 0x0018, uuid: 00002a26-0000-1000-8000-00805f9b34fb
handle: 0x0019, char properties: 0x02, char value handle: 0x001a, uuid: 00002a27-0000-1000-8000-00805f9b34fb
handle: 0x001b, char properties: 0x02, char value handle: 0x001c, uuid: 00002a28-0000-1000-8000-00805f9b34fb
handle: 0x001d, char properties: 0x02, char value handle: 0x001e, uuid: 00002a29-0000-1000-8000-00805f9b34fb
handle: 0x001f, char properties: 0x02, char value handle: 0x0020, uuid: 00002a2a-0000-1000-8000-00805f9b34fb
handle: 0x0021, char properties: 0x02, char value handle: 0x0022, uuid: 00002a50-0000-1000-8000-00805f9b34fb
handle: 0x0024, char properties: 0x1e, char value handle: 0x0025, uuid: 0000dfb1-0000-1000-8000-00805f9b34fb
handle: 0x0027, char properties: 0x1e, char value handle: 0x0028, uuid: 0000dfb2-0000-1000-8000-00805f9b34fb
handle: 0x002a, char properties: 0x18, char value handle: 0x002b, uuid: 0000dfb3-0000-1000-8000-00805f9b34fb
handle: 0x002d, char properties: 0x10, char value handle: 0x002e, uuid: 0000dfb4-0000-1000-8000-00805f9b34fb
handle: 0x0031, char properties: 0x02, char value handle: 0x0032, uuid: 0000dfb5-0000-1000-8000-00805f9b34fb


** GAP **
handle: 0x0001, uuid: 2800 - 00 18 1800 means Generic Access Service
handle: 0x0002, uuid: 2803 - 02 03 00 00 2a 02,0003,2a00 (R,hnd=3,type=device name)
handle: 0x0003, uuid: 2a00 - (blank)
handle: 0x0004, uuid: 2803 - 02 05 00 01 2a 02,0005,2a01 (R,hnd=5,type=appearance)
handle: 0x0005, uuid: 2a01 - 00 00
handle: 0x0006, uuid: 2803 - 0a 07 00 02 2a 0a,0007,2a02 (WR,hnd=7,type=Peripheral privacy flag)
handle: 0x0007, uuid: 2a02 - 00
handle: 0x0008, uuid: 2803 - 0a 09 00 03 2a 0a,0009,2a03 (WR,hnd=9,type=Reconnection Address)
handle: 0x0009, uuid: 2a03 - 00 00 00 00 00 00
handle: 0x000a, uuid: 2803 - 02 0b 00 04 2a 02,000b,2a04 (R,hnd=b,type=peripheral preferred connection parameters)
handle: 0x000b, uuid: 2a04 - 50 00 a0 00 00 00 e8 03 0050 00a0 0000 03e8 interval=100-200ms latency=0ms timeout=1000ms

** GATT **
handle: 0x000c, uuid: 2800 - 01 18 1801 means Generic Attribute Service
handle: 0x000d, uuid: 2803 - 20 0e 00 05 2a 02,000e,2a05 (R,hnd=e,type=service changed)
handle: 0x000e, uuid: 2a05 - Attribute can't be read
handle: 0x000f, uuid: 2902 - 00 00

** Device Info **
handle: 0x0010, uuid: 2800 - 0a 18 180a means Device Information
handle: 0x0011, uuid: 2803 - 02 12 00 23 2a 02,0012,2a23 (R,hnd=12,type=System ID)
handle: 0x0012, uuid: 2a23 - 62 c5 27 00 00 af 59 90
handle: 0x0013, uuid: 2803 - 02 14 00 24 2a 02,0014,2a24 (R,hnd=14,type=Model Number String)
handle: 0x0014, uuid: 2a24 - 44 46 20 42 4c 75 6e 6f 00 (DF BLuno)
handle: 0x0015, uuid: 2803 - 02 16 00 25 2a 02,0016,2a25 (R,hnd=16,Serial Number String)
handle: 0x0016, uuid: 2a25 - 30 31 32 33 34 35 36 37 38 39 00 (0123456789)
handle: 0x0017, uuid: 2803 - 02 18 00 26 2a 02,0018,2a26 (R,hnd=18,Firmware Revision String)
handle: 0x0018, uuid: 2a26 - 46 57 20 56 31 2e 30 00 (FW V1.0)
handle: 0x0019, uuid: 2803 - 02 1a 00 27 2a 02,001a,2a27 (R,hnd=1a,type=Hardware Revision String)
handle: 0x001a, uuid: 2a27 - 48 57 20 56 31 2e 30 00 (HW V1.0)
handle: 0x001b, uuid: 2803 - 02 1c 00 28 2a 02,001c,2a28 (R,hnd=1c,type=Software Revision Strin)
handle: 0x001c, uuid: 2a28 - 53 57 20 56 31 2e 30 00 (SW V1.0)
handle: 0x001d, uuid: 2803 - 02 1e 00 29 2a 02,001e,2a29 (R,hnd=1e,type=Mfg Name String
handle: 0x001e, uuid: 2a29 - 44 46 52 6f 62 6f 74 00 (DFRobot)
handle: 0x001f, uuid: 2803 - 02 20 00 2a 2a 02,0020,2a2a (R,hnd=20,type=IEEE Cert list)
handle: 0x0020, uuid: 2a2a - fe 00 65 78 70 65 72 69 6d 65 6e 74 61 6c (ffe0 experimental)
handle: 0x0021, uuid: 2803 - 02 22 00 50 2a 02,0022,2a50 (R,hnd=22,type=PnP ID)
handle: 0x0022, uuid: 2a50 - 01 0d 00 00 00 10 01

** BLUNO SPECIFIC **
handle: 0x0023, uuid: 2800 - b0 df dfb0
handle: 0x0024, uuid: 2803 - 1e 25 00 b1 df 1e,0025,dfb1 (NWWnRR,hnd=25,type= ??)
handle: 0x0025, uuid: dfb1 - 01 receivedCommand ()
handle: 0x0026, uuid: 2901 - 53 65 72 69 61 6c 20 52 63 76 (Serial Rcv)
handle: 0x0027, uuid: 2803 - 1e 28 00 b2 df 1e,0028,dfb2 (NWWnRR,hnd=28,type= ??)
handle: 0x0028, uuid: dfb2 - 02 DTR Port ???
handle: 0x0029, uuid: 2901 - 43 68 61 72 61 63 74 65 72 69 73 74 69 63 20 32 (Characteristic 2)
handle: 0x002a, uuid: 2803 - 18 2b 00 b3 df 18,002b,dfb3 (NW,hnd=2b,type= ??)
handle: 0x002b, uuid: dfb3 - Attribute can't be read Open USB??? receivedCommand gives (KeyPress:text)
handle: 0x002c, uuid: 2901 - 43 68 61 72 61 63 74 65 72 69 73 74 69 63 20 33 (Characteristic 3)
handle: 0x002d, uuid: 2803 - 10 2e 00 b4 df 10,002e,dfb4 (N,hnd=2e,type= ??)
handle: 0x002e, uuid: dfb4 - Attribute can't be read
handle: 0x002f, uuid: 2902 - 00 00
handle: 0x0030, uuid: 2901 - 43 68 61 72 61 63 74 65 72 69 73 74 69 63 20 34 (Characteristic 4)
handle: 0x0031, uuid: 2803 - 02 32 00 b5 df 02,0032,dfb5 (R,hnd=32,type= ??)
handle: 0x0032, uuid: dfb5 - Attribute requires authentication before read/write
handle: 0x0033, uuid: 2901 - 43 68 61 72 61 63 74 65 72 69 73 74 69 63 20 35 (Characteristic 5)
 
Upvote 0

kompiler

Member
Licensed User
Longtime User
All manager.GetCharacteristicProperties

B4X:
Private Sub Manager_Connected (Services As List)
    For i=0 To Services.Size-1
        manager.ReadData(Services.Get(i))
    Next
End Sub

Private Sub Manager_DataAvailable (Srv As String, Characteristics As Map)
    For i = 0 To Characteristics.Size - 1
        Log(" ")
        Log("Service: " & Srv)
        Log("Characteristic: " & Characteristics.GetKeyAt(i))
        Log("Properties: " & manager.GetCharacteristicProperties(Srv, Characteristics.GetKeyAt(i)))
    Next   
End Sub

Log

Discovering services.

Service: 00001801-0000-1000-8000-00805f9b34fb
Characteristic: 00002a05-0000-1000-8000-00805f9b34fb
Properties: 32

Service: 00001800-0000-1000-8000-00805f9b34fb
Characteristic: 00002a00-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 00001800-0000-1000-8000-00805f9b34fb
Characteristic: 00002a01-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 00001800-0000-1000-8000-00805f9b34fb
Characteristic: 00002a02-0000-1000-8000-00805f9b34fb
Properties: 10

Service: 00001800-0000-1000-8000-00805f9b34fb
Characteristic: 00002a04-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 00001800-0000-1000-8000-00805f9b34fb
Characteristic: 00002a03-0000-1000-8000-00805f9b34fb
Properties: 8

Service: 0000180a-0000-1000-8000-00805f9b34fb
Characteristic: 00002a23-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 0000180a-0000-1000-8000-00805f9b34fb
Characteristic: 00002a24-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 0000180a-0000-1000-8000-00805f9b34fb
Characteristic: 00002a25-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 0000180a-0000-1000-8000-00805f9b34fb
Characteristic: 00002a26-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 0000180a-0000-1000-8000-00805f9b34fb
Characteristic: 00002a27-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 0000180a-0000-1000-8000-00805f9b34fb
Characteristic: 00002a28-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 0000180a-0000-1000-8000-00805f9b34fb
Characteristic: 00002a29-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 0000180a-0000-1000-8000-00805f9b34fb
Characteristic: 00002a2a-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 0000180a-0000-1000-8000-00805f9b34fb
Characteristic: 00002a50-0000-1000-8000-00805f9b34fb
Properties: 2

Service: 0000dfb0-0000-1000-8000-00805f9b34fb
Characteristic: 0000dfb1-0000-1000-8000-00805f9b34fb
Properties: 30

Service: 0000dfb0-0000-1000-8000-00805f9b34fb
Characteristic: 0000dfb2-0000-1000-8000-00805f9b34fb
Properties: 30


I tried to setNotify with other services

B4X:
ServiceId = "00001801-0000-1000-8000-00805f9b34fb"
ReadChar = "00002a05-0000-1000-8000-00805f9b34fb"
manager.SetNotify(ServiceId,ReadChar,True)

Discovering services.
Setting descriptor. Success = true
writing descriptor: true



But I need DFB0 and DFB1

B4X:
ServiceId = "0000dfb0-0000-1000-8000-00805f9b34fb"
ReadChar = "0000dfb1-0000-1000-8000-00805f9b34fb"
manager.SetNotify(ServiceId,ReadChar,True)

Discovering services.
starter_manager_connected (java line: 140)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
at anywheresoftware.b4a.objects.BleManager2.setNotify(BleManager2.java:305)
at anywheresoftware.b4a.objects.BleManager2.SetNotify(BleManager2.java:295)
at b4a.example.starter._manager_connected(starter.java:140)
at java.lang.reflect.Method.invoke(Native Method)
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:148)
at android.app.ActivityThread.main(ActivityThread.java:5525)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
 
Upvote 0

kompiler

Member
Licensed User
Longtime User
I noticed an interesting thing during testing.

B4X:
Private Sub Manager_Connected (Services As List)
    ServiceId = "00001801-0000-1000-8000-00805f9b34fb"
    ReadChar = "00002a05-0000-1000-8000-00805f9b34fb"
    manager.ReadData(ServiceId)
End Sub

Private Sub Manager_DataAvailable (Srv As String, Characteristics As Map)
    Log(Characteristics.Get(ReadChar))
    manager.ReadData2(ServiceId,ReadChar)
End Sub

Log

Discovering services.
[B@8a660af
No matching characteristic found.


It is understandable.

B4X:
Private Sub Manager_Connected (Services As List)
    ServiceId = "0000dfb0-0000-1000-8000-00805f9b34fb"
    ReadChar = "0000dfb1-0000-1000-8000-00805f9b34fb"
    manager.ReadData(ServiceId)
End Sub

Private Sub Manager_DataAvailable (Srv As String, Characteristics As Map)
    Log(Characteristics.Get(ReadChar))
    manager.ReadData2(ServiceId,ReadChar)
End Sub

Log

Discovering services.
[B@98258cb
[B@b8fd8a8
[B@a329fc1
[B@4810366
[B@dbb6a7
[B@b5dd754
[B@d8876fd
[B@c09eff2
[B@e831643
[B@96b14c0
[B@f6a85f9
[B@cc3193e
[B@4b6d39f
[B@24cbcec
[B@6c488b5
[B@4538b4a
[B@13f0abb
[B@10e74d9
[B@3980e9e
[B@8668d7f
[B@201214c
[B@f688595
[B@e7276aa
[B@860829b
[B@7c50638
[B@e18e611
[B@8d95376
[B@f3aad77
[B@de04de4
[B@294d24d
[B@5ff3102
[B@822aa13
[B@4466450
[B@a694649
[B@7b35b4e
[B@983d46f
...


In log are random values without end. Bluno not send anything.
Sorry for my posts on this, but I really need this feature and I'm looking for solutions.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Search in both the internal libraries folder (Program Files (x86)\Anywhere Software\Basic4android\libraries) and the additional libraries folder and delete all references to the BLE2 library.
2. Download v1.35 and put it in the additional libraries folder.
3. No need to add any more information (other than the output I ask for). It is becoming difficult to understand this thread.

4.
What is the output of this code:
B4X:
Dim s As String = "0000dfb0-0000-1000-8000-00805f9b34fb"
Dim c As String = "0000dfb1-0000-1000-8000-00805f9b34fb"
Log("Properties: " & manager.GetCharacteristicProperties(s, c))
Log("a")
SetNotify(s, c, false)
Log("b")
SetNotify(s, c, True)
 
Upvote 0

kompiler

Member
Licensed User
Longtime User
Log

Ready: true
Discovering services.
Properties: 30
a
starter_manager_connected (java line: 150)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
at anywheresoftware.b4a.objects.BleManager2.setNotify(BleManager2.java:309)
at anywheresoftware.b4a.objects.BleManager2.SetNotify(BleManager2.java:295)
at b4a.example.starter._manager_connected(starter.java:150)
at java.lang.reflect.Method.invoke(Native Method)
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:148)
at android.app.ActivityThread.main(ActivityThread.java:5525)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)


I tried with Bluno UNO and Bluno BEETLE, the same result.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code doesn't set the notifications. You can see that the descriptors section is commented out:

SS-2016-12-26_12.48.59.png


The descriptor must be set for the notifications to work.

You can do the same thing by catching this error with a Try / Catch block.
 
Upvote 0

kompiler

Member
Licensed User
Longtime User
B4X:
Private Sub Manager_Connected (Services As List)
    Try
        manager.SetNotify(ServiceId,ReadChar,True)
    Catch
        Log(LastException)
    End Try
End Sub

Private Sub Manager_DataAvailable (Srv As String, Characteristics As Map)
    Dim BC As ByteConverter
    Log(BC.StringFromBytes(Characteristics.Get(ReadChar),"utf-8"))
End Sub

log

Discovering services.
(NullPointerException) java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference
test
working !!!!!!!!!!!!




1-31-happy-kid-stcloud1.jpg


Erel, thank you :)
 
Upvote 0
Top