How to simulate SensorHistory.getHeartRateHistory data?

The iterator only returns null, so how can I simulate the mock data? ActivityData simulation only seems to affect the ActivityMonitor

  • The use case for this is that I want to show only the last 5 minutes of data for tracking heart rate in between weight lifting sets. I modified my code to use a loop and search through the last 30 seconds of heart rate samples, but it's still not very consistent for some reason. The watch is on my wrist so I find it hard to believe it's not collecting a single sample for 30 seconds? Is the sensor just polling every minute or something?

    var lastHeartRate = null;
    var maxHeartRate = null;
    var minHeartRate = null;
    if (hrIterator != null) {
        var curr = hrIterator.next();
        while(curr != null && Time.now().compare(curr.when) < 31) {
            if (curr.data != null) {
                lastHeartRate = curr.data;
                break;
            }
            curr = hrIterator.next();
        }
        maxHeartRate = hrIterator.getMax();
        minHeartRate = hrIterator.getMin();
    }
    

  • You can request more samples than you need and then use "when" in the sample to select those in your timeframe

    On a reak device, you're probably only concerned with the newest 3-4 samples.

    On a real device, heart rate history samples are only saved every couple minutes.

    You can use Activity.getActivityInfo().currentHeartRate if you want the second-by-second data.

  • Activity.getActivityInfo() is definitely better. Is there any reason why someone would use SensorHistory over ActivityMonitor? They both seem to do the same thing so I defaulted to using SensorHistory, because ActivityMonitor suggests that it would only be active during activities, however after testing it seems to run in the background all the time just fine without an activity.

  • With Sensor history, you get a history, so you can do things like show a graph.

  • With ActivityMonitor I can also see the history though? What's the difference between the two?

  • The only difference I've ever seen with ActivityMonitor history and SensorHistory heart rate history is the value for a bad HeartRate (taking the watch off).  In once case it's null, the other 255.  It's the same "a couple minutes between samples"