Scripts (for GNU/Linux bash shell) to process activity data collected by Garmin smartwatches (verified with FR245)

1. The script heartrate.sh processes full-day fit files (they are compressed in a zip archive) and produces a 24-hour heart rate table and graph. Daily zip archive can be downloaded from Garmin connect. See for example 2020-09-07 heart rate.

2. The script trackfit.sh processes sport activity data (running, cycling, walking) and creates a pdf report with graphs (times, distances, geographic coordinates, heart rate, speed and altitude) and a data table in csv format. Data (zip or fit file) can be taken from the watch (via usb cable) or from the Garmin connect site. See for example activity Bici sab 5 set 2020 11-52-55.

3. The script trackgpx.sh processes sport activity data (running, cycling, walking) and creates a pdf report with graphs (times, distances, geographic coordinates, heart rate, speed and altitude) and a data table in csv format. Data (gpx file) can be download from the Garmin connect site. See for example activity running 18 sept 2020.

It is important to put the original data in an empty directory. The script should be in /usr/local/bin and the tool FitCSVTool.jar contained in the sdk must be in /usr/local/lib/.

These scripts are examples of how to get information from Garmin devices. First, they illustrate how to handle the timestamp16 field to determine the hour and day in which each information is detected.

In R this calculation is obtained from the formula:

t32[i]+bitAnd((t16[i]-t32[i]), strtoi("ffff",16))

and then taking into account that the initial time is 31.december.1989 00:00.

In addition, it is shown how to manage geographic coordinates in semicircle format.

Of course, all this information is found on the net and official sources.

Sure, it would have been better to avoid using the FitCSVTool.jar tool, but this would require a longer work in decoding the fit file. Otherwise you have to use the gpx file via the trackgpx.sh script (3), which is more portable and also works on android under termux. Futhermore, for this last script it is not necessary to have the FitCSVTool.jar tool and altitude data are correct (as many watches do not incorporate the barometric altimeter their readings are not accurate, sometimes completely random). In this third script the distance and speed are calculated based on the geographic coordinates and altitude contained in the gpx file.

D. S.