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

How to keep reading from a sensor

I am trying to write an app where I need to keep reading from the heart rate sensor in real time, but I am having trouble with 2 things.

 

1. I can't seem to take the current hrm.heartRate and store it in a variable - it always comes back null. Is this a known issue?

 

2. It only runs through the sensors 1 time before stopping the app. How can I keep the sensors reading over and over again?

Thanks

Best Answer
0 Votes
4 REPLIES 4

Hi @rhysshadow - see heart-rate api

Stop it when the display goes off is good practice.

 

Check if your app may be crashing.

Author | ch, passion for improvement.

Best Answer
0 Votes

I am doing that, but I am still not getting anything from hrm.heartRate?

 

I need it to be constantly running, because I am doing something when the heart rate gets out of range. It's a strange idea, I know, but that's what I am trying anyway.

I'm going to be measuring against a timer of 5 minutes.

So every 5 minutes, I will measure the heartrate, and check it and then do something based on the heartRate I've saved from last time, and then the new heartRate.

But the question remains - can I save it into a variable to check against the new timer?

Best Answer
0 Votes

@rhysshadow - your app stops running when the display is off and closes after 2 minutes of inactivity.

Author | ch, passion for improvement.

Best Answer
0 Votes

Oh I get it now!

I figured out a timer aspect, so it doesn't start unless it's been 5 minutes now, and then shuts off after a minute. So I've got it working!

Thanks for the help!

 

Best Answer
0 Votes