Toybox::SensorHistory question

Former Member
Former Member
How can I get the last temperature sample? thx for help
  • So far I've only been able to use getTemperatureHistory() in the sim, but when you request the iterator, try asking for a period of 1, and also the newest first. The sample you get has the latest temp in ".data".

    I've not gotten this to work on a watch yet (I can call getHeartrateHistory using SensorHistory though on a va-hr), so I'm not quite sure what it needs. For example, does it display the internal temperature data (I don't think all watches have and internal one), Tempe data, or both (start with internal until a tempe is connected)

    I suspect it's only the internal temp data... (which is impacted by skin temperature and things like long sleeve shirts.)
  • Former Member
    Former Member over 8 years ago
    hmmm.... why do .getMin() and .getMax() return in float in simulator while .data returns in number? :confused: :D
    Example:
    var min = mSensorIter.getMin(); // float in System.println(min)
    var max = mSensorIter.getMax(); // float in System.println(max)
    var previous = mSensorIter.next().data; // number in System.println(previous)
    // Prints (current elevation: 1364 max: 1371.599976 min: 914.400146)
  • Former Member
    Former Member over 8 years ago
    I believe the elevation values should all be floats. This will depend on the data type. (Heart Rate is an integer value)

    We will take a look at this.
  • How can I get the last temperature sample? thx for help


    Hi,


    I successfully did it on my app ... below is the sample code of what I did.

    //Check if SensorHistory supports the Device
    var lastTemp = 0;
    if ( Toybox.SensorHistory has :getTemperatureHistory )
    {
    //get the iterator... dont use the ":period" for options because I experienced memory leak using that one but still you can try
    var sample = Toybox.SensorHistory.getTemperatureHistory( {:order=>Toybox.SensorHistory.ORDER_NEWEST_FIRST} );
    //Check if No Data is available
    if (sample != null)
    {
    var nextInfo = sample.next();
    //Check for Invalid Value
    if ( nextInfo != null )
    {
    lastTemp = nextInfo.data;
    }
    }
    }



    Thanks,
    Mashake
  • One thing I've done is get all available samples, get the current temp out of the newest sample, but also use getMin() and getMax() to get the 4hr min and max as additional info.

    you just add the blue part. (you'll already getting all the samples)
    if (sample != null)
    {
    var min=sample.getMin();
    var max=sample.getMax();

    var nextInfo = sample.next();
    //Check for Invalid Value
    if ( nextInfo != null )
    {
    lastTemp = nextInfo.data;
    }
    }