Hi Team, I'm testing the Bleak - Bluetooth BLE example with a sensor, SDK here
the code below reads the data, but the output is incorrect, no idea how to do in B4J
thanks in advance
the code below reads the data, but the output is incorrect, no idea how to do in B4J
B4X:
[CODE=b4x]
24:AC:AC:01:41:03, Name=, Services=[0000180d-0000-1000-8000-00805f9b34fb, 0000feee-0000-1000-8000-00805f9b34fb], ServiceData={}
24:AC:AC:01:41:03, Name=Polar H10 0141033A, Services=[0000180d-0000-1000-8000-00805f9b34fb, 0000feee-0000-1000-8000-00805f9b34fb], ServiceData={}
adding 24:AC:AC:01:41:03
Connecting to: 24:AC:AC:01:41:03
connected!
Service: 00001800-0000-1000-8000-00805f9b34fb
Service: 00001801-0000-1000-8000-00805f9b34fb
Service: 0000180d-0000-1000-8000-00805f9b34fb
Service: 0000180a-0000-1000-8000-00805f9b34fb
Service: 0000180f-0000-1000-8000-00805f9b34fb
Service: 6217ff4b-fb31-1140-ad5a-a45545d7ecf3
Service: fb005c80-02e7-f387-1cad-8acd2d8df0c8
Service: 0000feee-0000-1000-8000-00805f9b34fb
Notification
Notification received: 00002a37-0000-1000-8000-00805f9b34fb
Data: T�
Heart rate: 21520
Parsed Heart Rate: 21520
Notification received: 00002a37-0000-1000-8000-00805f9b34fb
Data: U��
Heart rate: 21776
Parsed Heart Rate: 21776
Notification received: 00002a37-0000-1000-8000-00805f9b34fb
Data: U�
Heart rate: 21776
Parsed Heart Rate: 21776
Notification received: 00002a37-0000-1000-8000-00805f9b34fb
Data: T
Heart rate: 21520
Parsed Heart Rate: 21520
Notification received: 00002a37-0000-1000-8000-00805f9b34fb
Data: T��
Heart rate: 21520
Parsed Heart Rate: 21520
Notification received: 00002a37-0000-1000-8000-00805f9b34fb
Data: S�
Heart rate: 21264
Parsed Heart Rate: 21264
Notification received: 00002a37-0000-1000-8000-00805f9b34fb
Data: S
Heart rate: 21264
Parsed Heart Rate: 21264
B4X:
Private Sub BLE_CharNotify (Notification As BleakNotification)
Log($"Notification received: ${Notification.CharacteristicUUID}"$)
Log("Data: " & BytesToString(Notification.Value, 0, Notification.Value.Length, "ascii"))
Dim heartRate As Int = ParseHeartRate(Notification.Value)
Log("Parsed Heart Rate: " & heartRate)
For Each cp As ClientPage In Clients
If cp.mClient.mDevice.DeviceId = Notification.ClientUUID Then
cp.NotificationEvent(Notification)
End If
Next
End Sub
Private Sub ParseHeartRate(Value() As Byte) As Int
If Value.Length >= 2 Then
Dim heartRate As Int
heartRate = Bit.Or(Bit.ShiftLeft(Value(1), 8), Value(0))
Log("Heart rate: " & heartRate)
Return heartRate
End If
Return 0
End Sub
thanks in advance