Other ble2 question

Umberto Bianchi

Member
Licensed User
Longtime User
Hi,
I need to extract data from Geonaute BLE HRM heart rate monitor.

I need Heart rate measurement and battery level.

Somebody knows how to get this two type of data ?

Thank you.
 
After a normal initialization, scan and connection, you will receive a Connected event.
You must call SetNotify with the Service and Characteristics who contains the Heart Rate value and the Battery value

Code: Copy
Sub Manager_Connected (services As List)
connected = True
ConnectedServices = services

' bps notifier
manager.SetNotify("0000180d-0000-1000-8000-00805f9b34fb","00002a37-0000-1000-8000-00805f9b34fb",True)

    'insert a delay here

' battery notifyer
manager.SetNotify("0000180f-0000-1000-8000-00805f9b34fb","00002a19-0000-1000-8000-00805f9b34fb",True)

End Sub

When data changes, in the DataAvailable event you must choose the two characteristics you want.

Beats for minute are available in the second byte, and battery level at the first.

Code: Copy
Sub Manager_DataAvailable (ServiceId As String, Characteristics As Map)
Dim I As Int
Dim ValueData() As Byte
Dim HREValue,BattValue As Int

I=0
For Each id As String In Characteristics.Keys
  ValueData=Characteristics.GetValueAt(i)
  If ValueData.Length>0 Then
        'bps
        If Service="0000180d-0000-1000-8000-00805f9b34fb" And Characteristics.GetKeyAt(i)="00002a37-0000-1000-8000-00805f9b34fb" Then
            HREValue=Bit.And(0xFF, ValueData(1))
            HRE.Text=HREValue
        End If

        'battery
        If Service="0000180f-0000-1000-8000-00805f9b34fb" And Characteristics.GetKeyAt(i)="00002a19-0000-1000-8000-00805f9b34fb" Then
            BattValue=Bit.And(0xFF, ValueData(0))
            Battery.Text=BattValue
        End If

    End If
    I=I+1
  Next
End Sub

To get the battery level more than once, you must specifically read at the battery characteristic.

This does'nt work for the "beats per minute" characteristic.
If you “read” the “beats per minute” characteristic, you will obtain always a zero. You should expect the event with the correct data

Code: Copy
Public Sub ReadData
    ‘Read Battery
    manager.ReadData("0000180f-0000-1000-8000-00805f9b34fb")
End Sub
 
Last edited:
Upvote 0
Hi,
thanks for your code.
When use your code, all it's ok for the battery level. But for the properties "00002a37-0000-1000-8000-00805f9b34fb" it's no possible
because don't read it.
I scan my GEONAUTE BLE HRM with appropriate app(Bluepixel BLE Scan), and i need:
- Properties: notify
- Value: notifications or indications disabled
It's possible enabled it ?
 
Upvote 0
Do you have the characteristic with Assigned number = 0x2A37 in the Characteristics map?
If yes, the problem is only to read the value. As you can see with Bluepixel, the property is "Notification" only. If you try to read it, you will receive a Null. You can only expect for the DataAvailable event.
For the battery characteristic, the property is "Notification" and "Read", so you can read any times you want or expect for the event. Both works.

And for having the DataAvailable event, you may call manager.SetNotify with the Characteristic string (After connexion)
If you call SetNotify twice, you must wait at least 100ms between calls. This is explained in an other post. Begin calling it only for the "beats per minute" characteristic. It works

You can have more information here

Enable or disable notifications is the Client Characteristic Configuration Descriptor (CCCD). I think that manager.SetNotify is the responsible to manage this, so do not worry about this.
 
Last edited:
Upvote 0
I use this code
Code: Copy
Sub Manager_DeviceFound(Name As String, DeviceId As String, AdvertisingData As Map, RSSI As Double)  

   Log("DeviceFound" & CRLF & "  Name= " & Name & CRLF & "  ID= " & DeviceId)   
   Log("  AdvData= " & AdvertisingData & CRLF & "  RSSI= " & RSSI)   
   Log("Connecting...")
   Manager.Connect(DeviceId )
   
End Sub

Sub Manager_Connected(Services As List)
   Log("Connected:")
   Connected = True
   ConnectedServices = Services
   ReadData("0000180d-0000-1000-8000-00805f9b34fb")
End Sub

Sub ReadData(Service As String)
   Log("ReadData")
   Manager.ReadData("0000180d-0000-1000-8000-00805f9b34fb")  

End Sub
   
Sub Manager_DataAvailable (Serviceid As String, Characteristics As Map)
   Log("DataAvailable")
   Log("Service: " & Serviceid)
   Dim I As Int
   Dim ValueData() As Byte
   Dim HREValue  As Int
   
  
   Manager.SetNotify("0000180d-0000-1000-8000-00805f9b34fb","00002a37-0000-1000-8000-00805f9b34fb", True)
   ''''''
   I=0
   For Each id As String In Characteristics.Keys
    'ValueData=Characteristics.GetValueAt(i)
    Log("CharactKey:[" & i & "] " & Characteristics.GetKeyAt(i))
    Log(" ID: " & id)   

    'bps
    If Characteristics.GetKeyAt(i)="00002a37-0000-1000-8000-00805f9b34fb" Then
         ValueData=Characteristics.GetValueAt(i)
        HREValue=Bit.And(0xFF, ValueData(1))
  
         B_HR.Text = HREValue
         Log("HR: " & HREValue)
    End If


    I=I+1
   Next
   
End Sub

Sub B_Scan_Click
   Log("Scan")
   Manager.Scan(Null)
   
End Sub

Sub DiscoveryFinished
  Log("DiscoveryFinished")
End Sub

and have this log:
Scan
DeviceFound
Name= Geonaute BLE HRM
ID= D0:5F:B8:10:B9:CC
AdvData= (MyMap) {1=[B@42eb3e88, 2=[B@42eb3ef0, 9=[B@42eb3f30}
RSSI= -79
Connecting...
Discovering services.
Connected:
ReadData
DataAvailable
Service: 0000180d-0000-1000-8000-00805f9b34fb
CharactKey:[0] 00002a38-0000-1000-8000-00805f9b34fb
ID: 00002a38-0000-1000-8000-00805f9b34fb
 
Upvote 0
Here is a complete example. Is based on Erel's example with the specific characteristics of Heart Rate monitor.
Beats are refreshed automatically (and battery level if changed) and you can also ask for battery level whenever you want

I hope it works for you
 

Attachments

Upvote 0
Back
Top