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

How to read heart rate from Ionic's background data without firing up the sensor each time?

ANSWERED

If I just want to display the heart rate casually with no intention of displaying it real-time, how do I do that?

Can I create the HeartRateSensor object, but not call start/stop and just read the numerical data?

var hrm = new HeartRateSensor();
clock.granularity = "minute";
clock.ontick = () => {
$("heart").text = hrm.heartRate;
}

Will that value be updated without calling start()?
 

If I have to call start(), what is the consensus: should I call start+stop() every second in the clock.ontick() event or call start() on display-on event and stop() on display-off event?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

If you look at the Sensors example you will see that you can use 

setInterval(someFunction, timeInMilliseconds);

to make a function run periodically outside of ontick().

 

Here is code from my bell schedule watchface where I update the heartreat, step data, and period info a few times a minute.

clock.ontick = () => updateClock();
setInterval(updateClockData, 3000);
setInterval(updatePeriodData, 15000);

Full source code: https://github.com/cmspooner/Kearsarge-Time-for-Fitbit-Ionic

View best answer in original post

Best Answer
0 Votes
1 REPLY 1

If you look at the Sensors example you will see that you can use 

setInterval(someFunction, timeInMilliseconds);

to make a function run periodically outside of ontick().

 

Here is code from my bell schedule watchface where I update the heartreat, step data, and period info a few times a minute.

clock.ontick = () => updateClock();
setInterval(updateClockData, 3000);
setInterval(updatePeriodData, 15000);

Full source code: https://github.com/cmspooner/Kearsarge-Time-for-Fitbit-Ionic

Best Answer
0 Votes