Android Question BLE2 Read Byte Data

Martin Beukes

Member
Licensed User
Longtime User
Greetings,

I am trying to read byte data from a characteristic. Here is the map I received in DataAvailible:
(MyMap) {0000ffb1-0000-1000-8000-00805f9b34fb=[B@966af5, 0000ffb2-0000-1000-8000-00805f9b34fb=[B@320608a, 0000ffb3-0000-1000-8000-00805f9b34fb=[B@6ef56fb, 0000ffb4-0000-1000-8000-00805f9b34fb=[B@18ab318, 0000ffb5-0000-1000-8000-00805f9b34fb=[B@72fc171}

I need the raw byte data fro the characteristic ffb5 for my application. The current setting of ffb4 is 0x01, but I have no idea why it appears as B@18ab318 or even what that means. And when I use HexFromByteIi get 00 in the log.

What am I missing here?

Thanks,
Martin
 

MarcoRome

Expert
Licensed User
Longtime User
B4X:
Sub DataAvailable (Service As String, Characteristics As Map)
 For i = 0 To Characteristics.Size - 1
        Dim data1() As Byte =  Characteristics.GetValueAt(i)
        Log(bc.StringFromBytes(data1,"UTF-8"))
    Next
End Sub
 
Upvote 0

Martin Beukes

Member
Licensed User
Longtime User
As I mentioned above I am basically doing as you suggest but using BC.Hexfrombyte and am recieveing 00 instead of 01 (the current setting) and 1e (the perviously tried setting).

I will try the string decide and see. Will only be at my machine in about 2 hours. Bleeding is a little frustrating. Lol
 
Upvote 0

Martin Beukes

Member
Licensed User
Longtime User
Ok so here are my test results:
Found: TEST, ########, RSSI = -68, (MyMap) {1=[B@4f2a390, -1=[B@a85b489, 8=[B@2e5cc8e, 10=[B@3ff8caf, 3=[B@f0668bc, 0=[B@70c1045}
Discovering services.
Connected
(MyMap) {0000ffb1-0000-1000-8000-00805f9b34fb=[B@2f54a8, 0000ffb2-0000-1000-8000-00805f9b34fb=[B@1e26bc1, 0000ffb3-0000-1000-8000-00805f9b34fb=[B@282df66, 0000ffb4-0000-1000-8000-00805f9b34fb=[B@ae62a7, 0000ffb5-0000-1000-8000-00805f9b34fb=[B@791354}
CHR: 0000ffb1-0000-1000-8000-00805f9b34fb
VAL: [B@2f54a8
HEX:
STR:
CHR: 0000ffb2-0000-1000-8000-00805f9b34fb
VAL: [B@1e26bc1
HEX:
STR:
CHR: 0000ffb3-0000-1000-8000-00805f9b34fb
VAL: [B@282df66
HEX:
STR:
CHR: 0000ffb4-0000-1000-8000-00805f9b34fb
VAL: [B@ae62a7
HEX: 00
STR: ��
CHR: 0000ffb5-0000-1000-8000-00805f9b34fb
VAL: [B@791354
HEX:
STR:
C.V: anywheresoftware.b4a.objects.collections.Map$2@e6902fd
VAR: {0000ffb1-0000-1000-8000-00805f9b34fb=[B@2f54a8, 0000ffb2-0000-1000-8000-00805f9b34fb=[B@1e26bc1, 0000ffb3-0000-1000-8000-00805f9b34fb=[B@282df66, 0000ffb4-0000-1000-8000-00805f9b34fb=[B@ae62a7, 0000ffb5-0000-1000-8000-00805f9b34fb=[B@791354}

and my code:
B4X:
Public Sub DataAvailable(ServiceId As String, Characteristics As Map)
    Dim bc As ByteConverter
    Log(Characteristics)
   
   
   
    For i = 0 To Characteristics.Size - 1
        Dim data1() As Byte =  Characteristics.GetValueAt(i)
        Log("CHR: " & Characteristics.GetKeyAt(i))
        Log("VAL: " & Characteristics.GetValueAt(i))
        Log("HEX: " & bc.HexFromBytes(data1))
        Log("STR: " & bc.StringFromBytes(data1,"UTF-8"))
    Next
   
    Starter.BrrrReadout = Characteristics
    Log("C.V: " & Characteristics.Values)
    Log("VAR: " & Starter.BrrrReadout)
   
    CallSub(ListenerBeacon, "Disconnect")
End Sub

No idea what is wrong. 0000ffb4 reads as 0x01 in the oem tool and 0000ffb5 should have a LOT of data.
Any Ideas?
 
Upvote 0

Martin Beukes

Member
Licensed User
Longtime User
I am seeing all bits as 0. Why would this be?

CHR: 0000ffb5-0000-1000-8000-00805f9b34fb
VAL: [B@239c6bc
HEX: 0000000000000000000000000000000000000000
STR: ����������������������������������������
C.V: anywheresoftware.b4a.objects.collections.Map$2@e8f1645
VAR: {0000ffb1-0000-1000-8000-00805f9b34fb=[B@d0c2190, 0000ffb2-0000-1000-8000-00805f9b34fb=[B@5c45a89, 0000ffb3-0000-1000-8000-00805f9b34fb=[B@7267a8e, 0000ffb4-0000-1000-8000-00805f9b34fb=[B@c8da2af, 0000ffb5-0000-1000-8000-00805f9b34fb=[B@239c6bc}
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You shouldn't use GetKeyAt / GetValueAt.

B4X:
For Each key As String In Characteristics.Keys
Dim b() As Byte = Characteristics.Get(key)
Log(Key & ": " & bc.HexFromBytes(b))
Next

I am seeing all bits as 0. Why would this be?
This is the value received.
 
Last edited:
Upvote 0

Martin Beukes

Member
Licensed User
Longtime User
Hi Erel,

I am receiving a build error.

B4A line: 121
For Each key As String In Characteristics
javac 1.8.0_112
brrrr\main.java:1014: error: incompatible types: Map cannot be converted to IterableList
final anywheresoftware.b4a.BA.IterableList group3 = _characteristics;

B4X:
Public Sub DataAvailable(ServiceId As String, Characteristics As Map)
    Dim bc As ByteConverter
    Log(Characteristics)
   
    For Each key As String In Characteristics
        Dim b() As Byte = Characteristics.Get(key)
        Log(key & ": " & bc.HexFromBytes(b))
    Next
   
    CallSub(ListenerBeacon, "Disconnect")
End Sub
 
Upvote 0
Top