Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Does HeartRateSensor frequency do anything?

It looks like using the frequency option for HeartRateSensor doesn't do anything. No matter if I set the frequency 5 or 0.5, the onreading callback called once in every second using my Versa 3 (with SDK 6.1). In the simulator it's called on every change regardless how frequent it is.

 

The official API reference doesn't even mention the option frequency. Maybe it's not implemented?

 

My code:

 

let heartSensor: HeartRateSensor;

if (HeartRateSensor && appbit.permissions.granted('access_heart_rate')) {
  heartSensor = new HeartRateSensor({ frequency: 0.5 });

  heartSensor.onreading = () => {
    const rate = heartSensor.heartRate;
    heartRateTxt.text = rate === null ? 'Ø' : `${rate}`;
    console.log((Date.now() / 1000 % 100).toFixed(2)); // debug
  };

  display.onchange = () => {
    if (bodySensor?.present) {
      display.on ? heartSensor.start() : heartSensor.stop();
    }
  };
} else {
  heartRateTxt.style.visibility = 'hidden';
}

 

 

Actually my goal is to create a clockface with heart rate on it which only updates every four seconds. I know I can still use setInterval method, but I find it cumbersome and not clean in the world of events/callbacks.

 

Best Answer
0 Votes
4 REPLIES 4

Hi @HeyJ0e  -  it's mentioned here

 

However you are going to run into problems with the display timeout. Once the timeout occurs nothing will be done with the heart rate information, so it is a good idea to turn it off.

 

What question your post does raise also, is what is the default frequency?

 

Generally using the default and turning if off when the display is off you won't save much battery by adding special code when it is on.

 

The OS Simulator may not be representative of what happens on a real watch.

Author | ch, passion for improvement.

Best Answer
0 Votes

 

Hi Guy,

 

Thank you for your answer. Yes, I saw the heart-rate guide, but there's still no detailed information about frequency option.

 

I'm not sure if I get your point correctly. Are you saying that I shouldn't use any JS hacking with setInterval or setTimeout, right? Because that's my goal as well.

 

My problem is that it looks like the frequency option does not work on my Versa 3. The HeartRateSensor's reading event fires roughly in every second, regardless of the desired frequency.

Best Answer
0 Votes

I think the frequency parameter is only applicable to batched sensor events.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@HeyJ0e  - you are right about the documentation mentioning CPU usage as an issue.

 

But as the watch JS will only be working for 8 to 10 seconds or less at a time, it is probably not a major issue as you stop it when the display is off.

 

Presumably you can stop and start the heart rate sensor to control the number of readings if you plan to use a longer display timeout.

 

The example documentation does show frequency of 1 (without a batch) which presupposes other valus should work, so it is a good question.

 

As @Gondwana  says it is intended for use with batch (,in the other example).

 

Have you tried using the frequency with a batch of 1 to see if that makes a difference?

 

Whether a frequency of less than 1 is available is not mentioned either.

 

Author | ch, passion for improvement.

Best Answer
0 Votes