Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get proper values from Polar heart rate monitor

Tags:

java

android

My android application is getting data from Polar Heart Rate Monitor through Bluetooth connection. My problem is that I am getting such a string: ��������������������������������������������������

My code for getting the data:

 final Handler handler = new Handler();
    final byte delimiter = 10; //This is the ASCII code for a newline character

    stopWorker = false;
    readBufferPosition = 0;
    readBuffer = new byte[1024];
    workerThread = new Thread(new Runnable()
    {
        public void run()
        {
            while(!Thread.currentThread().isInterrupted() && !stopWorker)
            {
                try
                {
                    int bytesAvailable = mmInputStream.available();
                    if(bytesAvailable > 0)
                    {
                        byte[] packetBytes = new byte[bytesAvailable];
                        mmInputStream.read(packetBytes);
                        for(int i=0;i<bytesAvailable;i++)
                        {
                            byte b = packetBytes[i];
                            if(b == delimiter)
                            {
                                byte[] encodedBytes = new byte[readBufferPosition];
                               // System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
                                final String data = new String(encodedBytes, "ASCII");

                                readBufferPosition = 0;

                                handler.post(new Runnable()
                                {
                                    public void run()
                                    {
                                        pulsText.setText(data);
                                    }
                                });
                            }
                            else
                            {
                                readBuffer[readBufferPosition++] = b;
                            }
                        }
                    }
                }
                catch (IOException ex)
                {
                    stopWorker = true;
                }
            }
        }
    });

    workerThread.start();

I tried to change this line in few ways but I am still getting incorrect data:

 final String data = new String(encodedBytes, "ASCII");

How can I solve this issue ?

Please help !!!

like image 801
erni Avatar asked Apr 12 '12 18:04

erni


People also ask

How do I calibrate my Polar heart rate monitor?

To reset your heart rate sensor: Remove the battery. Press the metal snaps that attach to the strap with your fingers for at least 10 seconds. Wait 30 seconds and then put the battery back in.

How accurate are Polar heart rate monitors?

Well, that's hard to say, according to Polar. The company's current H7 at H10 straps are accurate to +/- 1 millisecond, according to the company, so in very good conditions they are quite similar.

How do you accurately measure heart rate?

At the wrist, lightly press the index and middle fingers of one hand on the opposite wrist, just below the base of the thumb. At the neck, lightly press the side of the neck, just below your jawbone. Count the number of beats in 15 seconds, and multiply by four. That's your heart rate.

How do you read heart rate data?

A normal resting heart rate for adults ranges from 60 to 100 beats per minute. Generally, a lower heart rate at rest implies more efficient heart function and better cardiovascular fitness. For example, a well-trained athlete might have a normal resting heart rate closer to 40 beats per minute.


1 Answers

The sensor doesn't give you printable strings (like e.g. NMEA does) but binary data that you need to parse. You could look into the MyTracks Polar Sensor data parser for inspiration.

You are using available and read incorrectly (but the way you use you could have luck most of the time).

like image 150
Hauke Ingmar Schmidt Avatar answered Nov 03 '22 12:11

Hauke Ingmar Schmidt