onTimeReset and onTimeStop. Data not saved in FIT file when calling Field.setData

Hi,

I want to save some Session data once the activity has ended, and I do it inside onTimeReset event. I save lap data too, and I do it inside onTimerLap event. This lap data has to be saved when stop button has pressed, so you can see last lap data and the total data along the activity. Something like that:

function onTimerLap() {
LapField1.setData(...);
LapField2.setData(...);
...
}

function onTimerStop() {
LapField1.setData(...);
LapField2.setData(...);
...
SessionField1.setData(...);
SessionField2.setData(...);
...
}

function onTimerReset() {
LapField1.setData(...);
LapField2.setData(...);
...
SessionField1.setData(...);
SessionField2.setData(...);
...
}

When run in simulator all works fine and the Stop an Reset events are called and the code inside then executed, as in Lap event. But when run in watch (Forerunner 735XT with last firmware update) only the Lap event is executed, and neither the Stop nor Reset events are called, or the code inside them is not executed.

There is a very strage thing about Timer events. If I copy the code inside the event to a function, and then call this function, the function is not called from inside the events. If there is some code before the function call, it's executed, but not the function calling and the code after the funcion call. And this error occurs both on simulator and watch. Function saveLapData() is not called from inside none of the events. So I have to repeat same code inside the events instead of call another funtion to do the job.

function saveLapData() {
LapField1.setData(...);
LapField2.setData(...);
...
}

function onTimerLap() {
Code here is executed properly;
saveLapData; // not executed
}

function onTimerReset() {
Code here is executed properly;
saveLapData; // not executed
SessionField1.setData(...); // not executed
SessionField2.setData(...); // not executed
...
}

I've tried with 2.x.x and 3.x.x SDK versions, and the same with all of them.

Regards,
  • Hi

    Just found out myself, that onTimerReset gets called in the SIM but not on my 935 )-:

    Shouldn't this be reported as a bug, at least the SIM should give the same result as the real device in such basic events.

  • So sad I reproduced it on fenix7 and epix2pro these so-called high-end models. This is my bug report. https://forums.garmin.com/developer/connect-iq/i/bug-reports/ontimerreset-not-called-in-a-datafield-on-fenix7 

  • do you know if calling setData for a lap field will write out if you do it within the onTimerStop() callback?

    i have a specific use case in mind where I only need to call setData once regardless of how many laps there are (bc I just want the columns to show up in Garmin Connect), and I would prefer to just call it within onTimerStop bc I have some extra logic for determining if the fields should be written

  • No. Just read the original question

  • Hey, I just wanted to say thanks for all the help you’ve provided in the forums, I’ve learned a lot from some of your posts.

    Sometimes your tone comes off harsh, this makes the experience of reading the forums less enjoyable and discourages positive productive interactions.

    This isn’t the first time I’ve felt this way after reading one of your replies, so I figured it was worth sharing this feedback.

    If you re-read the original post and then my follow-up question, I think you'll see that the original post doesn’t actually address the technically nuanced point I was asking about.

  • Read the 1st response from 7 years ago. That applies to all callbacks.

    Maybe it'll work for onTimerStop according to that comment, but the question then is if it works that way on all watches.

  • do you know if calling setData for a lap field will write out if you do it within the onTimerStop() callback?

    It might set data for the final lap, not the lap summary data row as you asked about elsewhere. As far as I know, it's impossible for CIQ fields to set data for the lap summary row. Connect is smart enough to know which native session field correspond with a given native lap, but there doesn't seem to be a corresponding mechanism to tie together CIQ lap and session fields.

    But back to your actual question and my answer (which is "maybe")..My reasoning is that the general rule for FIT lap data seems to be that setData() has to be called before the end of the lap in question. e.g. You have to call setData() for Lap 1's data before the first onTimerLap() event (a common noob mistake is to call it within the first onTimerLap() event itself)

    Ofc, the final lap is a little different, as you never get an onTimerLap() event for the end of the final lap in any case - the final lap ends when the activity ends. 

    So I don't know what happens if the user stops the timer (for the first and only time) and subsequently ends the activity. Does the "end of the final lap" occur just before/at onTimerStop() or does it occur "after" onTimerStop()? If we knew the answer to that question, we could probably tell for sure without trying.

    TL;DR maybe, but the only way you'll know for sure is if you try it for yourself.

  • It might set data for the final lap,

    ok gotcha yeah makes sense, will give it a shot and let you know! I was mainly asking in case you tried already and knew the answer hah

  • Yeah sorry, I'm not sure, I don't think I've tried that exact scenario.

    > I have had success writing session data in onTimerStop()

    Based on this, it's not too crazy to imagine that you could write data for the final lap in onTimerStop() as well. 

    Let me know if it works!

    Ofc, not to state the obvious, but if the goal is to only write data for the final lap, you have no way of preventing previous laps from being set in some situations, as you can't prevent the user from starting the timer after they stop it.

  • Ok just gave this a shot and it worked! At least on my Forerunner 955.

    So when you setData for a lap message in onTimerStop() it does indeed work and the lap message gets written for that final lap.