Android Question Polar H7 Data

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

postasat

Active Member
Licensed User
Longtime User
Thank you Erel,

now I can read battery level.

Heart Rate measurement (2A37) is still not available.

I should activate the "notify" status on Polar H7, to get the real time heart rate data.

Notify has to be turned on by changing the Characteristic Configuration at handle 0x0012 i.e. UUID 0x2902.
The data returned is from handle 0x0011 i.e. UUID 0x2a37 which is the characteristic that provides Heart Rate Measurement.

Can you give me an example how to write data on polar using BLE example to activate notify, and how to read 0x2a37 every seconds ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

postasat

Active Member
Licensed User
Longtime User
You're right,
it's the Polar battery level.

I can read the data about battery level, it's the value of characteristic 0x2a19.

Now I need to have the heart rate measurement data.
The heart rate measurement is not available in a normal data reading.
I think that must be activate.
After activation, Polar HRM should send every second the data, as notify.
I need an example how to write data on polar to activate notify, and how to read 0x2a37 notify, every seconds.

Thank you.
 
Upvote 0

postasat

Active Member
Licensed User
Longtime User
I activate manager.SetNotify for the service 180d and the characteristic 0x2a37 (after a standard read data of all characteristics).
B4X:
manager.ReadData2("0000180d-0000-1000-8000-00805f9b34fb","00002a37-0000-1000-8000-00805f9b34fb")
The log return "No matching characteristic found".
In the service 180d I can only read the characteristic 0x2a38 (Body Sensor Location).
I think that Notify has to be turned on (on Polar), but I'm not sure.
The Polar example for ios set this.
#define HEART_RATE_SERVICE @"180D"
#define HEART_RATE_MEASUREMENT @"2A37"

The Polar example for ios how to read heart rate measurement data is not so clear (for me).
http://developer.polar.com/wiki/H6_and_H7_Heart_rate_sensors
Seems that they don't send nothing to start notify.
I'm lost...

Thank you.
 
Upvote 0

postasat

Active Member
Licensed User
Longtime User
I tried to call SetNotify with the following code (I put it in starter, activated with a button in "Main").
B4X:
manager.SetNotify("0000180d-0000-1000-8000-00805f9b34fb","00002a37-0000-1000-8000-00805f9b34fb",True)
After activated this command nothing happen, DataAvailable event is never raised.

Maybe I misunderstanding the use of SetNotify command and how to read the notify from Polar, can you give me some example ?
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
I tried to call SetNotify with the following code (I put it in starter, activated with a button in "Main").
B4X:
manager.SetNotify("0000180d-0000-1000-8000-00805f9b34fb","00002a37-0000-1000-8000-00805f9b34fb",True)
After activated this command nothing happen, DataAvailable event is never raised.

Maybe I misunderstanding the use of SetNotify command and how to read the notify from Polar, can you give me some example ?
Are you using the latest update of the library? See this post....just in case...
https://www.b4x.com/android/forum/threads/ble2-setnotify.62042/#post-392018
 
Upvote 0

postasat

Active Member
Licensed User
Longtime User
With the new library update SetNotify is Ok.
Polar transmitt HR data every seconds and I can read it.

If can help somebody else, the code I added on DataAvailable is the following:
B4X:
'Measure
If keyread = "00002a37-0000-1000-8000-00805f9b34fb" Then
   testoconvhrm = conv.HexFromBytes(Characteristics.GetValueAt(i))
end if

byte2 = testoconvhrm.CharAt(2)
byte3 = testoconvhrm.CharAt(3)
   
Dim realhr As Int
Dim bpm As String
bpm = byte2 & byte3
realhr = Bit.ParseInt(bpm, 16)

Log("HEART RATE: " & realhr)

To start notify I put in Starter the following code, that I activate with a button from Main:
B4X:
Public Sub writeData1
    'Enable
    manager.SetNotify("0000180d-0000-1000-8000-00805f9b34fb","00002a37-0000-1000-8000-00805f9b34fb",True)
    Log("Set Notify")
End Sub

To stop notify I put in Starter the following code, that I activate with a button from Main:
B4X:
Public Sub writeData2
    'Disable
    manager.SetNotify("0000180d-0000-1000-8000-00805f9b34fb","00002a37-0000-1000-8000-00805f9b34fb",False)
    Log("UnSet Notify")
End Sub

Thanks to everybody !!!
 
Upvote 0

Denny Hopp

Member
Licensed User
Longtime User
Does anyone have example code using the BLE2 WriteData to write data to a BLE device? My reads are working fine but the writes don't work. Thanks!
 
Upvote 0
Top