Save value for statistic in Garmin connect

Hello!

My first simple Datafield App is running on my Edge 1040 and working.

Now I would like to display the stat at the end of an activity in Garmin connect, like other apps:

I would like to save the values:

Time with zero cadence

Distance with zero cadence

My datafield looks like this:

How can I add this info in the workout?

I think I need to Activity Recording?

https://developer.garmin.com/connect-iq/core-topics/activity-recording/

I use this xml:

<strings>
    <string id="AppName">Rollzeit</string>

    <string id="zeropower_label">Zeit im Freilauf</string>
    <string id="zeropower_units">N(s)</string>

    <string id="zerodistance_label">Distanz im Freilauf</string>
    <string id="zerodistance_units">N(s)</string>
</strings>

and a second:

<fitContributions>
    <fitField id="0" displayInChart="false" sortOrder = "0" precision="2" dataLabel="@Strings.zeropower_label" unitLabel="@Strings.zeropower_units"/>
    <fitField id="1" displayInChart="false" sortOrder = "1" precision="2" dataLabel="@Strings.zerodistance_label" unitLabel="@Strings.zerodistance_units"/>
</fitContributions>

Is this so far correct? But how can I store the value at the end of the workout?

Thank you!

  • I added this code line, but not visible in Garmin connect:

    class:

        const ZEROPOWER_FIELD_ID = 0;
        const ZERODISTANCE_FIELD_ID = 1;
        hidden var mzeroPowerField;
        hidden var mzeroDistanceField;

    function initialize()

         mzeroPowerField = createField("current_zeropower",
                ZEROPOWER_FIELD_ID, 
                FitContributor.DATA_TYPE_FLOAT,
                {:mesgType=>FitContributor.MESG_TYPE_RECORD, :units=>"N" }
            );
    
            mzeroPowerField.setData(0);
    
            mzeroDistanceField = createField("current_zerodistance",
                ZERODISTANCE_FIELD_ID, 
                FitContributor.DATA_TYPE_FLOAT,
                {:mesgType=>FitContributor.MESG_TYPE_RECORD, :units=>"N" }
            );
    
            mzeroPowerField.setData(0);
            mzeroDistanceField.setData(0);

    function compute(info as Activity.Info) as Numeric or Duration or String or Null
                    mzeroPowerField.setData(zeroPower.value());
                    mzeroDistanceField.setData(zeroDistance);
    Did I need a save() command?
    I tried a ride but nothing shown in Garmin connect page
  • How are you testing this?

    It won't work with a sideload (connecting the USB cable and copying the PRG to the device) because the app needs to be in the store for developer FIT field graphs to appear in Connect.

    In order to test this, you need to upload your app to the store as a beta app (check the box which says “this app is for testing purposes”): [https://developer.garmin.com/connect-iq/core-topics/beta-apps/]

    It should be approved instantly and nobody else will be able to see it or download it by any means.

    When you’re ready to release the app for real, you’ll have to change the app ID in manifest.xml (from the command palette in VS Code: “Monkey C: Regenerate UUID”)

  • Hello!

    Yes, I already upload as beta and test live with the edge 1040. After saving the activity it don´t display in Garmin connect.

    It is saved in FIT file. I checked the file:

    Best Power 20min are displayed in Garmin connect. This is another data field from the IQ store.

    Why don´t display my info?

  • how can I store the value at the end of the workout?
    After saving the activity it don´t display in Garmin connect.

    You set the fields' mesgType as FitContributor.MESG_TYPE_RECORD, which means they're meant to be recorded continuously during the activity (like pace or HR). (idk why you're seeing them in a session message tbh.)

    Because the fitContributions XML specifies displayInChart="false", then it's not surprising that MESG_TYPE_RECORD fields wouldn't be displayed at all.

    If you change the mesgType to MESG_TYPE_SESSION, then you should see these values in the activity summary (end of workout stats).

  • Hello 

    I already changed, but still don´t display.

    My code:

    (are the xml correct? I added just the file resources.xml. Or did I need to register the file somewhere?)

    resources.xml

    <resources>
        <fitContributions>
            <fitField id="0" displayInChart="false" sortOrder = "0" precision="0" dataLabel="@Strings.zeropower_label" unitLabel="@Strings.zeropower_units"/>
            <fitField id="1" displayInChart="false" sortOrder = "1" precision="0" dataLabel="@Strings.zerodistance_label" unitLabel="@Strings.zerodistance_units"/>
        </fitContributions>
    </resources>

    strings,xml

    <strings>
        <string id="AppName">Rollzeit</string>
    
        <string id="zeropower_label">Zeit im Freilauf</string>
        <string id="zeropower_units">W</string>
    
        <string id="zerodistance_label">Distanz im Freilauf</string>
        <string id="zerodistance_units">W</string>
    </strings>

    function initialize

        function initialize() { 
            SimpleDataField.initialize();
            label = "Rollzeit";
    
            mzeroPowerField = createField("Zeit im Freilauf",
                ZEROPOWER_FIELD_ID, 
                FitContributor.DATA_TYPE_STRING,
                {:mesgType=>FitContributor.MESG_TYPE_SESSION, :count=>10 }
            );
    
            mzeroPowerField.setData("0:00 min");
    
            mzeroDistanceField = createField("Distanz im Freilauf",
                ZERODISTANCE_FIELD_ID, 
                FitContributor.DATA_TYPE_UINT16,
                {:mesgType=>FitContributor.MESG_TYPE_SESSION, :units=>"m" }
            );
    
            mzeroPowerField.setData("0:00");
            mzeroDistanceField.setData(0);

    in function compute

                    mzeroPowerField.setData(secondsToTimeString(zeroPowerTotal.value()) + " min");
                    mzeroDistanceField.setData(zeroDistance);

    Edit:

    in the .iq File is the fit_contributions.json with:

    {
      "datafields" : [ {
        "id" : 0,
        "chart-visible" : false,
        "activity-visible" : false,
        "lap-visible" : false,
        "chart-title-key" : null,
        "label-key" : "zeropower_label",
        "unit-label-key" : "zeropower_units",
        "sort-order" : 0,
        "precision" : 2,
        "fill-color" : null
      }, {
        "id" : 1,
        "chart-visible" : false,
        "activity-visible" : false,
        "lap-visible" : false,
        "chart-title-key" : null,
        "label-key" : "zerodistance_label",
        "unit-label-key" : "zerodistance_units",
        "sort-order" : 1,
        "precision" : 2,
        "fill-color" : null
      } ],
      "strings" : {
        "default" : {
          "zeropower_label" : "Zeit im Freilauf",
          "zeropower_units" : "W",
          "zerodistance_label" : "Distanz im Freilauf",
          "zerodistance_units" : "W"
        }
      }
    }

  • Sorry, neglected to mention you have to add displayInActivitySummary=true to the FitContributor XML for each field that you want to display in the activity summary. (The corresponding field in fit_contributions.json is "activity-visible", which is currently false.)

    From the CIQ dev page on recording that you linked (https://developer.garmin.com/connect-iq/core-topics/activity-recording/):

  • Thanks, this was the problem. Now it displaying!

    Thanks