Data Field not writing to fit and/or showing chart in connect?

I wrote a quick datafield keeping track of the battery level and discharge rate, first intention was to just display but thought 'ah well, why not write to fit as well to display it in a chart on connect'. I am finding that out now...

What I have done (showing for 1 field):

1. Added 'Fit Contributor' permission to the manifest

2. I added a 'fitcontributions.xml' file in a 'fitcontributions' subfolder of the resources folder (tried a raw fit.xml file in resources before as well) containing the following:

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


3. Added relevant entries to the strings.xml

<string id="LevelChartTitle">Battery Level</string>
<string id="LevelLabel">battery_level</string>
<string id="LevelUnit">%</string>


4. Added the following code to the View.mc sourcefile

Added global
using Toybox.FitContributor as Fit;
using Toybox.System as Sys;

and inside the class (extending UI.DataField):
var batField;
const BATTERY_FIELD_ID = 0;

Then in 'function initialize()':
batField = createFieId( "battery_level",
BATTERY_FIELD_ID,
Fit.DATA_TYPE_FLOAT,
{:mesgType=>Fit.MESG_TYPE_RECORD, :units=>"%"}
);



In 'function compute(info)':
var battery = Sys.getSystemStats().battery;
batField.setData(battery);


The battery value is also shown in the field and is visible, it's a float...

Am I missing something? The chart doesn't pop up on connect, when I load the .fit file in monkeygraph nothing happens either... No errors, no messages, nothing.

Anyone a clue?
  • it's createField not createFieId (you have a capital I)
    Also look on garmin connect (the website version), on garmin connect mobile displaying graph items are flaky (sometimes it shows, sometimes it doesn't)
  • it's createField not createFieId (you have a capital I)
    Also look on garmin connect (the website version), on garmin connect mobile displaying graph items are flaky (sometimes it shows, sometimes it doesn't)


    Lol, yeah... sorry about that!

    Somehow I got a JSON error when trying createFieId with the lowercase L so I made it a capital i... Thought it might be a codeword but as you seem to be able to type it I guess it's not. This forum drives me mad sometimes with it's errors and illogical messages.

    In the code it's lowercase L though ;) And it is not showing on the web interface... didn't even try the mobile app yet.
  • Lol, yeah... sorry about that!

    Somehow I got a JSON error when trying createFieId with the lowercase L so I made it a capital i... Thought it might be a codeword but as you seem to be able to type it I guess it's not. This forum drives me mad sometimes with it's errors and illogical messages.

    In the code it's lowercase L though ;) And it is not showing on the web interface... didn't even try the mobile app yet.


    I wouldn't trust Connect at all for determining if your data was written to the FIT file. I would download the FIT file from the Connect/Simulator and run it against FitToCSV tool from the FIT SDK. There are too many variances to do testing from there. If you see the data in the FIT file then we can work through the rest but make sure the data is actually getting to the file first. Have you tried checking that way first?
  • I wouldn't trust Connect at all for determining if your data was written to the FIT file. I would download the FIT file from the Connect/Simulator and run it against FitToCSV tool from the FIT SDK. There are too many variances to do testing from there. If you see the data in the FIT file then we can work through the rest but make sure the data is actually getting to the file first. Have you tried checking that way first?


    Thanks for the tip, didn't try fit2csv yet but did load it in fitrepairtool but couldn't really find anything there... will give FitToCSV a try!

    *Edit*

    And I do see the fields inside the csv, not sure where to go from there but good to see the values at least seem to be in the .fit... Will be looking at it tomorrw some more.
  • Did you already upload the app to the store? (Required to get it to work) beta apps should work too
  • I think that might be it! Just uploaded it to test (but now the field wasn't shown in my watch).. I had an earlier version uploaded without saving but wanted to test this one first, guess I have/had to upload it afterall in order to test.

    I read about that here:

    https://www.programmableweb.com/news...ent/2016/11/14

    But overlooked it in the developer docs? Will be experimenting more with it! (Also managed to get it to show up in the monkeygraph tool... so getting somewhere).

    Thanks all for thinking along and helping out!

    *EDIT*

    And that was it! Now the graphs indeed pop up! Problem solved, thanks all :) Now time for some sleep.