Garmin Time Returned on Vivoactive HR

My current code: https://github.com/DailyWeightFatControl/garmin_watchface/blob/watchapp-test_comm1/source/DFC_garmin_watchfaceView.mc

Please note that just like this works:
HRSample.when.value();
HRSample.data);


function sendHR() {
Comm.setMailboxListener(mailMethod);
var listener = new CommListener();

var HRSensorHistoryIterator = SensorHistory.getHeartRateHistory(
{
:period => 10,
:order => SensorHistory.ORDER_NEWEST_FIRST
});

var HRSample = HRSensorHistoryIterator.next();
var dataArray = []; // array size will be increased as needed using .add()

// Starting building the command response
dataArray.add(HISTORIC_HR_COMMAND);
dataArray.add(HISTORIC_HR_COMMAND);
while (HRSample != null) {

dataArray.add(HRSample.when.value());
dataArray.add(HRSample.data);

HRSample = HRSensorHistoryIterator.next();
}

System.println("timeNow " + Time.now().value());
System.println("dataArray " + dataArray);

// Transmit command response
Comm.transmit(dataArray, null, listener);
}


The code running on emulator, all seems ok:
Copying file.... 94% complete
Copying file.... 97% complete
Copying file.... 99% complete
Copying file.... 100% complete
File pushed successfully
Connection Finished
Closing shell and port
Found Transport: tcp
Connecting...
Connecting to device...
Device Version 0.1.0
Device id 1 name "A garmin device"
Shell Version 0.1.0
timeNow 1482242743
dataArray [-24576, -24576, 1482242743, 80, 1482242676, null, 1482242609, 84, 1482242542, 81, 1482242475, 76, 1482242408, 75, 1482242341, 79, 1482242274, 83, 1482242207, 85, 1482242140, 82]
send er 1482242747
timeNow 1482242748
dataArray [-24576, -24576, 1482242743, 80, 1482242676, null, 1482242609, 84, 1482242542, 81, 1482242475, 76, 1482242408, 75, 1482242341, 79, 1482242274, 83, 1482242207, 85, 1482242140, 82]
send er 1482242749
timeNow 1482242753
dataArray [-24576, -24576, 1482242743, 80, 1482242676, null, 1482242609, 84, 1482242542, 81, 1482242475, 76, 1482242408, 75, 1482242341, 79, 1482242274, 83, 1482242207, 85, 1482242140, 82]
send er 1482242755
Complete
Connection Finished
Closing shell and port


But when running on Vivoactive HR 2:
  • Have you written a test program on the vivoactive_hr to display the current time? You should be able to do it pretty easily.

    function onUpdate(dc) {

    var cx = dc.getWidth() / 2;
    var cy = dc.getHeight() / 2;

    var now = Time.now().value();

    dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
    dc.clear();

    dc.drawText(cx, cy, Gfx.FONT_SMALL, now.toString(), Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
    }


    Do you get a reasonable values shown for that?

    If so, you might try displaying the when values from the SensorHistorySample on the device. If you see reasonable values on the device, then there is some sort of problem that is causing data loss when communicating back to the mobile app.

    Travis
  • Interesting... In the sim, you are getting the time in "unix time" (number of seconds since Midnight Jan 1 1970) for both when and Time.now().value() (which is correct), but on the watch, you get different numbers, but..... there is a pattern the numbers are 95 apart in each case, and it happens that's about the time I've seen between HR readings in history by timing when it changes, as well as by math - 148 samples, is about 4 hours, and shown that way in the HR widget: 4hrs=14400 seconds. 14400/148=97

    So, you may be getting the time, but not in "unix time". Travis will remember the days of "garmin time" showing up at times in some calls in the early CIQ days. Internally time was kept like "unix time", but it wasn't based on Jan 1, 1970 - it used the year that Garmin was founded instead. (1990?)

    I'm wondering if that's what's happening here - "when" is in "Garmin time" and not "unix time (that's why it's a smaller number, and in "seconds per year", the difference is about 20 years - 1990?). It's a bug I'll say.

    But you might be able to do a work around before it's fixed. Using the "every 95 seconds", you'd know the time for each reading, without sending the time for each one. If the first reading is at X, the second is at X-95, the third X-(95*2), etc (you may be off up to 94 seconds on the exact time, and it may (or probably will) need to be adjusted for other devices.

    Or, since it looks like a constant difference (like I said, it looks to be about 20 years in seconds), add that value to the "when" value you see on the va-hr before sending it to the phone.

    Or, not even pass the time stamps. Just the frequency (so you vary it based on the type of watch, and can determine it by subtracting to adjacent "whens" (You wouldn't care if it's unix or garmin time for that)
  • Internally time was kept like "unix time", but it wasn't based on Jan 1, 1970 - it used the year that Garmin was founded instead. (1990?)

    Yes, I believe Jim is right. This problem has cropped up a few times. Have a look here.

    Or, since it looks like a constant difference (like I said, it looks to be about 20 years in seconds), add that value to the "when" value you see on the va-hr before sending it to the phone.

    Yes.

    var two_years_ago = Time.now().add(new Time.Duration(-2 * Gregorian.SECONDS_PER_YEAR));

    var when = ...;
    if (when.lessThan(two_years_ago)) {
    // looks like we have a bug. work around it
    when = when.add(new Time.Duration(20 * Gregorian.SECONDS_PER_YEAR - Gregorian.SECONDS_PER_DAY));
    }


    Travis
  • Former Member
    Former Member over 8 years ago
    I have moved these posts to our Bug Reports thread. Can you fill out any of the other missing info according to the Bug Reports forum rules so I can create a ticket?

    Link: https://forums.garmin.com/showthread.php?366516-Bug-Reports-Forum-Rules

    This will help us to determine if this is on the CIQ side of things or in the device integration.

    Thank you,
    -Coleman
  • o A Descriptive Title (i.e. “Simulator Freezes Launching App in Eclipse”)
    "when" for a HR sample from ActMon.getHeartrateHistory() is in "garmin time" and not System time on a va-hr

    o The Environment:
    -Operating System or Device (including OS number or Software version of device)
    SDK 2.2.1, Windows 10, va-hr with 3.30 FW , Eclipse Neon

    o A detailed description of the issue
    See: https://forums.garmin.com/showthread.php?366632-Garmin-Time-Returned-on-Vivoactive-HR&p=929499#post929499

    o Steps to reproduce the issue
    With the code here, run in the sim, and you'll see that "system time" and "when time" are close to each other (both are "unix time"). Run it on the watch, and you see a difference of about 20 years ("garmin time" for "when"). You may have to wait a couple minutes on the va-hr for it to make a history entry with the HR. I did this as a watch-app, and the code to demonstrate this is in onUpdate(). Other than that, a 1 sec timer is used to update the display.

    o Any applicable additional information
    I'll .zip the whole project if you want and email it. Let me know

    o A code sample that can reproduce the issue (in email only if preferred)

    The is can also be used as is to see if it's also a problem on other watches with whr. (fr 235, fr3-hr, etc)

    using Toybox.WatchUi as Ui;
    using Toybox.Graphics as Gfx;
    using Toybox.System as Sys;
    using Toybox.ActivityMonitor as ActMon;
    using Toybox.Time.Gregorian as Calendar;

    class GTHRHView extends Ui.View {
    var width,height,center;
    var timer;

    function initialize() {
    View.initialize();
    timer= new Timer.Timer();
    timer.start( method(:onTimer), 1000, true );
    }

    // Load your resources here
    function onLayout(dc) {
    width=dc.getWidth();
    center=width/2;
    height=dc.getHeight();
    }

    // Called when this View is brought to the foreground. Restore
    // the state of this View and prepare it to be shown. This includes
    // loading resources into memory.
    function onShow() {
    }

    function onTimer() {
    Ui.requestUpdate();
    }


    // Update the view
    function onUpdate(dc) {
    dc.setColor(Gfx.COLOR_BLACK,Gfx.COLOR_BLACK);
    dc.clear();
    dc.setColor(Gfx.COLOR_WHITE,Gfx.COLOR_BLACK);
    var unix=Time.now().value();

    dc.drawText(center,20,Gfx.FONT_SMALL,"unix:"+unix,Gfx.TEXT_JUSTIFY_CENTER);

    var hrh=ActMon.getHeartRateHistory(1,true);
    var hr="--";
    var when=0;
    if(hrh!=null) {
    var hrs=hrh.next();
    if(hrs!=null && hrs.heartRate!=null && hrs.heartRate!=ActMon.INVALID_HR_SAMPLE) {
    hr=hrs.heartRate.toString();
    when=hrs.when.value();
    }
    }
    dc.drawText(center,40,Gfx.FONT_SMALL,"when:"+when,Gfx.TEXT_JUSTIFY_CENTER);

    var diff=unix-when;
    dc.drawText(center,60,Gfx.FONT_SMALL,"diff: "+diff,Gfx.TEXT_JUSTIFY_CENTER);

    var years=diff.toFloat()/Calendar.SECONDS_PER_YEAR;
    dc.drawText(center,80,Gfx.FONT_SMALL,"years: "+years,Gfx.TEXT_JUSTIFY_CENTER);

    dc.drawText(center,130,Gfx.FONT_SMALL,"hr: "+hr,Gfx.TEXT_JUSTIFY_CENTER);
    }

    // Called when this View is removed from the screen. Save the
    // state of this View here. This includes freeing resources from
    // memory.
    function onHide() {
    }

    }
  • Former Member
    Former Member over 8 years ago
    Thanks Jim,

    I've got it set up now. We will check it out.

    -Coleman
  • This was addressed at some point prior to the 2.4.1 SDK release. Please create a new thread if the issue pops back up--thanks!