The interplay of Activities and getHearRateHistory

I am experimenting with a watch face that shows some historical HR metrics (times spent in specified user set ranges) for the present day.  I have the face and settings sorted out and everything seems to work when using the watch face when going about day to day business.  

This morning, I did a workout and logged it as an activity on the watch (i.e., I started a treadmill activity).  After saving that and returning to my watch face, none of the HRs from that session were processed in the history of the watch face. 

The face uses getHeartRateHistory to get a sample of HR's.  The sample range either starts from midnight (if the face is just initialising) or starts from the time getHeartRateHistory was last called (Time.Moment stored as a var).  This idea being it prevents the need to read and process the entire day's HRs every time the function is called.

Now, my issue could be

1 - The HR data from the stored treadmill activity is not 'kept' in the same place as getHeartRateHistory accesses which would explain why my workout HRs were not processed.  - I think this would mean what I am trying to do is not feasible since to do it reliably would require a web API call which a watchface can't do.

2 - The watch face function calling getHeartRateHistory is still called despite the watchface no longer being in the foreground but fails to get the HRs (perhaps they are not available during Activities?).  But the failed call still updates the var where it stores the time getHeartRateHistory was called.  The upshot of this would be that when the watchface is back in the foreground it only calls for history since the last time stamp and so none of the activity HRs are processed. 

3 - Some other coding error of mine

Because this relies on the interplay of different screens, I am working on a real device which, in turn, is fiendishly difficult to debug - so any suggestions welcome.

Also Is there a set of documents that explains the technical aspects of things like heart rate history and activities?  I have read (somewhere on here I think) that getHeartRateHistory is essentially reset if the watch reboots but can find precious little other information. The API docs give its usage but not (for example) how long a data set it will store (does it reset to 0 items after a sync or does it always store the current day for example).  

Any help/advice is greatly appreciated.

  • Ok, one thing to keep in mind, is when you use SensorHistory and heart rate,, samples are only saved about every two minutes,  You can determine the exact rate by comparing "when" in two adjacent samples.  Which means the data isn't real time and some things won't show.  In the sim, this is canned data so you do want to test on a real device.

    Also, the OHR has two modes.  24/7 which is less accurate but uses less battery, and activity mode.  It's easy to see which mode is being used.  You just peek under the back of the watch, and if the green leds are on solid, it's in activity mode.

    While the HR is saved to the fit file as often as every second if you are recording, you have no way to access that data in the fit file from a CIQ app 

    As far as debugging on a real device, see the New Developer FAQ.  You can create a log file and the results of something like a println are saved there