09-10-2020 05:48
09-10-2020 05:48
I have a clockface that reads the heart rate bpm every 8 seconds and stores it in an array so I can draw a graph of the my heart rate for the past 10 minutes.
I initiate the sensor with const hrm = new HeartRateSensor({ frequency: 8 });
In addition to populating the array every 8 seconds, I would like to read the hrm.heartRate in order to populate a text field. But I would like to do this every second.
So my question is, how can I make the frequency of hrm 8 when the display is off, and change it to 1 when the display is on? Is it simply a case of hrm.frequency = 1?
Best Answer09-10-2020 13:54
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
09-10-2020 13:54
You can use setOptions()
https://dev.fitbit.com/blog/2019-10-29-announcing-fitbit-os-sdk-4.0/#sensor-apis
Best Answer09-10-2020 23:08
09-10-2020 23:08
Thanks @JonFitbit Interestingly, although I initiate the sensor with frequency: 8, I'm still able to get varying heartRate values far more frequently than 8 seconds, for example if I read them on the clock tick. Likewise, if I use the code below, I'll get an almost continuous stream of values
hrm.addEventListener("reading", () => {
console.log(`Current heart rate: ${hrm.heartRate}`);
});
Could you please clarify what the frequency option is actually doing?
Best Answer09-10-2020 23:13 - edited 09-10-2020 23:14
09-10-2020 23:13 - edited 09-10-2020 23:14
Ah, I think I see my misunderstanding. Frequency is not seconds between readings, it's the number of readings per second (hz)!
09-10-2020 23:13
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
09-10-2020 23:13
I know you're not talking to me, but I think the answer is that the frequency just sets how often your event handler (callback) function is called. You'll probably find that readings only change every three seconds or so, at best.
Best Answer09-10-2020 23:17
09-10-2020 23:17
Yes, thanks Gondwana. I realised my error just after posting. Of course, the clue is in the word "frequency"!
Best Answer