How to write time information into a FIT file

After finishing an activity, Garmin Connect shows standard fields like heart rate and pace in graphs. Time information, like in pace, is displayed in the format "5:35" on the y axis. I wonder how it is possible to write data to the FIT file to be displayed like this, because strings seem not to be possible to be written to FIT?

  • I can't believe I'm the only one who ever tried to do this. I implemented a workaround with floating point numbers, but there has to be a better way. How is garmin doing that in their standard graph overview? So obviously there must be a way to achieve this! 

  • I'm not sure if this is on subject, but time stamps are written to FIT files as seconds since Garmin's "Epoch" of Jan 1 2000 (unlike Unix's Dec 31 1970).

  • What i try to do is writing time data (e. g. Pace) to a fit file so in the graph it gets formated like "5:30 min/km" on the y axis and elapsed time of the activity on the x axis. It's not allowed to write it as strings, unfortunately. Is there a way to do this? 

  • Unfortunately not. Garmin doesn't store pace in the FIT-file, they store speed (m/s). Depending on user preferences for measurement units and activity type it is rendered differently.

    I tried a lot of different settings (nativeNum and units) for storing an alternate speed value and render it the same as pace but it doesn't work. I think that this is done by Garmin Connect for Garmins own speed field only. I agree this is unfortunate since there are interesting ways of showing pace. Have a look at this example from Runalyze with moving average and grade adjusted pace:

  • Are you setting :count for createField if you use a string?  The default size is 1.  See the API doc:

    Optional parameters that can be specified for Field creation

    • :count — (Toybox.Lang.Number) — 

      The number of elements to add to the Field if it is an Array

      • This is also the maximum combined size of strings plus null terminators if the type is DATA_TYPE_STRING (Default 1)

      • Apps are limited to 256 total bytes per message

      • Data fields are limited to 32 bytes per message

      • Messages larger than the limit will result in a "New Field out of memory for FIT data" error.

  • Hi Tobias, yes, I agree with what you say, I checked the profiles in the FIT SDK documentation and it seems there is no datatype usable for the purpose of showing the pace in the format Garmin uses in the Connect App. I think you can use a workaround to use a floating point number to show 5:45 in a way like 5.45, but I'm afraid the first question a user will ask will be "do I have to transform this number to a pace value myself?". And somehow understandable, because 5.45 ist not really what you'd expect as a pace value. Well, I have to think now about how to do it. Showing a pace graph would be nice, though.

  • Hi Jim, yes, I tried that, the problem is that you are not allowed to use STRING datatypes for this type of recording activity (FitContributor.MESG_TYPE_RECORD), it throws an error as that:

    Error: Invalid Value
    Details: STRING data types can not be used with the RECORD FIT message type!

    I think it would be okay to use strings for a summary, but for a graph it seems Garmin does not allow this.

  • That's what I do - change the ":" to "." for FIT files. I explain this in my app description and that's OK, of course, because all users always fully read and understand the descriptions don't they?

  • In fact I think this workaround is pretty good, I'm thinking about using this approach in my datafield, too! But just between you and me: people are giving an app a 1-star-rating because they don't know how to install a datafield, so no, i don't think all users read and understand the app descriptions ;-) 

  • As I understand, but I can be wrong, the Toybox documentation is incorrect here because it says:

      "Apps are limited to 256 total bytes per message":

    I think it should read:

      "Sessions are limited to 256 total bytes per message".

    I created string-fields with a :count=>22 which results in strings of 23 length (inclusive the null terminator).

    At the 12th string-field in one session, which brings the total of bytes just over 256, the error

      “New Field out of memory for FIT data”

    comes.

    But if I subdivide the strings in a plurality of sessions, such that the total number of bytes per session stays under 256, no error happens although the total number of bytes in the same app is over 256.

    (The problem hereby is, but that is another topic, that the result is a plurality of FITfiles. For a workout-summary this is not appropriate).