Documentation and example on FitContributor

I just today switched to SDK 2.1 and I would like to start playing with the fit files through the FitContributor method.
Where can I find some clear documentation or working example to start?
Thanks in advance.
  • You can start by looking at Toybox::FitContributor and Toybox::ActivityRecording::Session in the API docs, and we also have some information published in the Programmer's Guide. There is actually a sample app we put together, but it's not being distributed with the SDK right now (I'd like to include something like it in a future release). I'd be happy to forward a sample to you for you to study--just contact me directly at [email][email protected][/email].
  • Thank you very much for your interest Brandon...ok so far so good,I did the followings steps and it looks like it's working because the compiler ends the job...I still have no check if the field I added is really in the fit file but I'll do soon.
    1 - session = Record.createSession({:name=>"XXXXXX", :sport=>Record.SPORT_TRAINING , :subSport=>Record.SUB_SPORT_CARDIO_TRAINING});
    first create a new session (ok of course)
    2 - field = session.createField("field", 0, FitContributor.DATA_TYPE_UINT16, {:mesgType => FitContributor.MESG_TYPE_SESSION});
    from the documentation I understand that with the MESG_TYPE_SESSION option the field will be added once at the end of the session,and it's what I need
    3 - field.setData(myVar);
    here is where I set the var that will be saved in the field on the fit file
    4 - session.save();
    at last

    now from the point 2 I assume that I must call point 3 just before to save the session on orders to have the last value of myVar saved in the fit file...am I correct or I'm missing something?
    thank you on advance,
  • Hi Brandon. I will start to take a look at the new features and I would appreciate if you send the Fit Contributor sample to me.

    Just sent a mail to you.

    Cheers,

    Robinson
  • The MoxyDataField example shows what you need to do.
  • I've been able to verify that my data is making it to the FIT file using FIT SDK, but I haven't been able to get the monkeygraph tool working and I don't see any mention of my data on connect.garmin.com when I upload my workouts. Is connect.garmin.com currently processing user data from fit developer fields?

    Rob
  • I've been able to verify that my data is making it to the FIT file using FIT SDK, but I haven't been able to get the monkeygraph tool working and I don't see any mention of my data on connect.garmin.com when I upload my workouts. Is connect.garmin.com currently processing user data from fit developer fields?

    Rob


    Do you have the metadata for the FitContributor Data Entered in to the Resources file like in the sample in the SDK below?

    This is why you need to load a .iq file into MonkeyGraph and this is why Garmin Connect only shows Fit Contributor Data from Apps that have been loaded in the App store. They both need this metadata.

    <resources>
    <fitContributions>
    <fitField id="0"
    displayInChart="true"
    sortOrder="0"
    precision="2"
    chartTitle="@Strings.hemoglobin_concentration_label"
    dataLabel="@Strings.hemoglobin_concentration_label"
    unitLabel="@Strings.hemoglobin_concentration_units"
    fillColor="#FF0000" />

    <fitField id="1"
    displayInChart="false"
    sortOrder = "1"
    precision="2"
    displayInActivityLaps="true"
    dataLabel="@Strings.hemoglobin_concentration_label"
    unitLabel="@Strings.hemoglobin_concentration_units" />

    <fitField id="2"
    displayInActivitySummary="true"
    sortOrder = "2"
    precision="2"
    dataLabel="@Strings.hemoglobin_concentration_label"
    unitLabel="@Strings.hemoglobin_concentration_units" />

    <fitField id="3"
    displayInChart="true"
    sortOrder = "3"
    precision="2"
    chartTitle="@Strings.hemoglobin_percentage_label"
    dataLabel="@Strings.hemoglobin_percentage_label"
    unitLabel="@Strings.hemoglobin_percentage_units"
    fillColor="#00FF00" />

    <fitField id="4"
    displayInChart="false"
    sortOrder = "4"
    precision="2"
    displayInActivityLaps="true"
    dataLabel="@Strings.hemoglobin_percentage_label"
    unitLabel="@Strings.hemoglobin_percentage_units" />

    <fitField id="5"
    displayInActivitySummary="true"
    sortOrder = "5"
    precision="2"
    dataLabel="@Strings.hemoglobin_percentage_label"
    unitLabel="@Strings.hemoglobin_percentage_units" />
    </fitContributions>
    </resources>
  • Do you have the metadata for the FitContributor Data Entered in to the Resources file like in the sample in the SDK below?


    Yeah I do:

    <fitContributions>
    <fitField id="0" displayInChart="true" sortOrder="0" precision="2"
    chartTitle="@Strings.ItemNameLabel" displayInActivitySummary="true" dataLabel="@Strings.ItemNameLabel"
    unitLabel="@Strings.Units" fillColor="#FF0000" />
    </fitContributions>


    Also, I can see the fields show up in the Connect mobile app under "Connect IQ" of any given workout. Maybe I'm just don't know where to look on the Connect website. I'll keep poking around. Also, as far as I can tell the monkeygraph tool only works with .iq files not .prg and it's only ever crashed on me. YMMV.

    UPDATE: I'm now seeing my Fit developer fields on Garmin Connect under the activity details. I must have missed it before, sorry for wasting time here. Either way it's working now.

    Rob
  • Dynamic chart unit label for FIT Developer Fields

    I've got my FIT Developer fields working and showing up in the mobile apps and web site, but I'm now wondering how to create dynamic chart unit labels based off of user modified properties. I've tried a few things:

    1. In the <fitContributions> block, reference the @Properties.ID of the property that I want to use:

    <fitContributions>
    <fitField id="0" displayInChart="true" sortOrder="0" precision="2"
    chartTitle="@Strings.ItemNameLabel" displayInActivitySummary="true" dataLabel="@Strings.ItemNameLabel"
    unitLabel="@Properties.ItemName" fillColor="#FF0000" />
    </fitContributions>


    I get the following error:

    BUILD: ERROR: Fit contribution id=0's 'unitLabel' references non existent string ID '@Properties.ItemName'
    BUILD: WARNING: String reference '@Properties.ItemName' should use the format '@Strings.<id>' (@[email protected])

    2. Reference a string resource that then references the property I'd like to use:

    <strings>
    <string id="Units">@Properties.ItemName</string>
    </strings>

    <properties>
    <property id="ItemName" type="string">Pizza</property>
    </properties>

    <fitContributions>
    <fitField id="0" displayInChart="true" sortOrder="0" precision="2"
    chartTitle="@Strings.ItemNameLabel" displayInActivitySummary="true" dataLabel="@Strings.ItemNameLabel"
    unitLabel="@Strings.Units" fillColor="#FF0000" />
    </fitContributions>



    This compiles and even saves things to the FIT file as expected. Using the FitSDK, I can examine all aspects of the FIT file and see that in the Session data and all other data, "Pizza" is now the unit label for my developer field. When I upload the data to Connect.Garmin.com I see "@Properties...." listed as my unit label. @Properties.ItemName is not saved any where in the FIT file, so the Garmin website must be using my resources.xml file to generate this label. I guess the site is not fully parsing the resource file correctly.

    Also, I've specified the unit label when creating the data field:

    itemField = SimpleDataField.createField(App.getApp().getProperty(Ui.loadResource(Rez.Strings.ItemName)), ITEM_FIELD_ID, FitContributor.DATA_TYPE_FLOAT, { :mesgType=>FitContributor.MESG_TYPE_SESSION, :units=> labelString });

    Any ideas on how I might make this work?
  • When you have FitContrib data, the definition you create is included as a .json file in the .iq file. When Garmin Connect or GCM gets a .fit from your app, it gets the data in the .json from the app store, as it's not in the .fit. So, what's displayed is based on what you submitted in the .iq, and and can't be changed in the app. While you called it "@property..." That's now the string is was in the .iq sent to the store, and will be used as the label. (this is why monkeygraph needs a .iq and not a .prg.)

    You can't dynamically change a label.
  • I had concluded (I'm not positive I'm correct) that having dynamic chart unit labels, data labels, or chart titles in Garmin Connect can't be done as it is.

    My understanding is that the information in the resources.xml file is not automatically written in each .FIT file. It only gets communicated to GC when you upload the App to the App Store.

    It would be a nice feature to have an option in the resources file to direct Garmin Connect to use data from the .FIT file for these parameters instead of using a fixed string.
    - For the dataLabel or ChartTitle, have the option to use the createField(name) string from the FIT file
    - For the unitsLabel, have the option to use the createField(:units) option string from the FIT file

    For Moxy, I write the Sensor Number and the Sensor Location to the createField(name) string. I don't see anyway to display this with the Moxy data graph in GC. We're planning to support multiple sensors at once so it would be helpful to see this string because it will show which sensor was on the left or right leg for example.