Android Tutorial BLE - Heart Rate Monitor

Discussion in 'Tutorials & Examples' started by Erel, Feb 29, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    HeartRateMonitor class searches for peripherals with the heart rate service (0x180D).

    Once a peripheral device is found and connected then a notification is set for the heart rate measurement characteristic (0x2A37).

    The DataAvailable event is raised whenever the heart rate changes. The heart rate is parsed from the raw data and printed to the logs.

    Note that this class is also compatible with B4i.

    It starts searching for devices when the HeartRateMonitor class is initialized.

    B4A libraries: BLE2 and ByteConverter
    B4i libraries: iBLE and iRandomAccessFile

    Attached Files:

    JohnK, hani bassam, Beja and 9 others like this.
  2. Ivan Lo Presti

    Ivan Lo Presti New Member Licensed User

    i just started with BLE. I am trying to figure out a way to write commands to the BLE device.
    the example code only shows data read. where could I find a "send"function so i can test my device?
    thanks very much.
  3. Erel

    Erel Administrator Staff Member Licensed User

  4. canalrun

    canalrun Well-Known Member Licensed User

    In the HeartRateMonitor.bas file there is the subroutine UUID.

    In Android it forms the UUID by concatenating the service with other numbers

    Private Sub UUID(id As StringAs String
    #if B4A
    Return "0000" & id.ToLowerCase & "-0000-1000-8000-00805f9b34fb"
    #else if B4I
    Return id.ToUpperCase
    #End If
    End Sub
    Where do the other numbers, 0000XXXX-0000-1000-8000-00805f9b34fb, come from?

    Are these from the UUID of a known device that is being scanning for? Or, some other?

  5. Erel

    Erel Administrator Staff Member Licensed User

    All standard UUIDs look like: 0000XXXX-0000-1000-8000-00805f9b34fb

    In Android you need to use the long format and in iOS you need to use the short format.
    f0raster0 likes this.
  6. postasat

    postasat Member Licensed User

    I need to extract from the Heart Rate Measurement the following data:
    - RR-Interval

    I found this information:

    There is a bit that control if data are present, the bit4 of the flag is about RR-Interval presence.

    I found this note about RR:
    (the bit3 of the flag is the presence of energy expended data)

    How can I do, to extract them ?
    Can you help me with code or implement this function in the class ?

    Thank you,
  7. Erel

    Erel Administrator Staff Member Licensed User

    You can use the GetBit sub to get the bit value:

    You need to check whether the energy field is present or not, the length of the rate field (see the example code) and then find the two bytes of RR-Intercal.

    ByteConverter.HexFromBytes is useful to understand the message structure.
    postasat likes this.
  8. Beja

    Beja Expert Licensed User

    Hi Erel,
    Thanks for this very important class.. I am very interested in this and want to incorporate it into a project., but my knowledge of these devices is next to zero.
    Is there any popular device or any device known to be compatible with this class? is it a pcb module or a packaged device (in housing box).
    It would be great of there is a picture of a compatible device.
    Best, -B
  9. Erel

    Erel Administrator Staff Member Licensed User

    Any heart rate monitor that supports BLE will work as this is a standard protocol.
    Beja and johndb like this.
  10. Sapta

    Sapta Member Licensed User

    how to use this sample?
  11. Erel

    Erel Administrator Staff Member Licensed User

    Sapta likes this.
  12. kreativa

    kreativa Member Licensed User

    Hi everybody,
    need help!
    I wrote a procedure to read heart rate monitor, and it works!
    Now i need to read multiple heart rate. When manager_dataAvaible is called i can read the characteristic with the heart rate measure from all the devices but i don't know the name of the device i'm reading.

    How can i do to know the device name in manager_dataavaible?

    victormedranop likes this.
  13. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for your question.
  14. victormedranop

    victormedranop Well-Known Member Licensed User

    Can you share ?

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice