Its not possible, in fit file power meter’s voltage at the start of the ride and at the end have the same value.
At least there is a field for that. Perhaps in future.
Its not possible, in fit file power meter’s voltage at the start of the ride and at the end have the same value.
At least there is a field for that. Perhaps in future.
Thanks, Pepe. The fit file I’m looking at is showing different voltage figures at the start and end timestamps, which is what got me thinking in the first place about grabbing the last row for the device type rather than the first. Perhaps your PM battery has slower drain rate than the one I happened to have been using for the ride in this file (4iiii).
Please try now
@jspira Thanks for asking, because I hadn’t realized that’s what my script was pulling out. Here’s an updated version of my script that pulls the last recorded voltage:
{
let voltage;
// find all 'bikePower' entries in the table
const powers = icu.fit.device_info.filter(
(di) => (di.device_type?.value === 11)
);
// entries _should_ be in increasing timestamp order but make sure
// NOTE: not sure how to convert the 'timestamp' into a date/time as
// `new Date(timestamp.value)` yields the same date/time while the numbers
// are clearly increasing and fitfileviewer.com is able to convert them;
// but it doesn't really matter as the higher the number, the later in the
// ride it is
powers.sort((left, right) => (left.timestamp.value - right.timestamp.value));
if (powers.length <= 0) {
const di = powers.at(-1); // last entry is nearest the end of the ride
// console.log('di ' + di); // prints all fields in debug format
// console.log(di.battery_voltage?.value); // prints voltage value
if (typeof di.battery_voltage?.value === 'number') {
voltage = di.battery_voltage.value;
}
if (typeof voltage === 'number' && !Number.isNaN(voltage)) {
console.log('voltage=', voltage);
} else {
voltage = undefined;
}
}
if (voltage === undefined) {
console.error('voltage not found');
}
voltage;
}
Looking at my data (Garmin Rally 200 power pedals), I see that the V at the start is always higher than the V at the end, however, the next ride’s starting V is back up near what the previous ride’s starting V was.
So I’m thinking I might tweak this to calculate the average of all recorded voltages and use that for tracking whether I’m near the ~2.55V where I typically get a “low battery” warning.
And here’s the average Shimano Di2 battery level over the course of the entire ride:
{
let level; // charge level, 0-100 range
const devices = icu.fit.device_info.filter(
(di) => (
di.manufacturer?.value === 41 && // SHIMANO
di.device_type?.value === 1 // Di2 battery (best guess)
)
);
// entries _should_ be in increasing timestamp order but make sure
// NOTE: not sure how to convert the 'timestamp' into a date/time as
// `new Date(timestamp.value)` yields the same date/time while the numbers
// are clearly increasing and fitfileviewer.com is able to convert them;
// but it doesn't really matter as the higher the number, the later in the
// ride it is
devices.sort((left, right) => (left.timestamp.value - right.timestamp.value));
if (devices.length > 0) {
const levels = devices.filter(
(di) => {
// console.log('di ' + di); // prints all fields in debug format
return (
typeof di.battery_level?.value === 'number' &&
!Number.isNaN(di.battery_level.value)
);
}
).map((di) => di.battery_level.value);
console.log(`levels=${levels.length}:[${levels.join(', ')}]`);
if (levels.length > 0) {
// calculate the average over the entire ride
level = levels.reduce((acc, v) => (acc + v), 0) / levels.length;
console.log(
`🟢 Levels(${levels.length}): avg=${level}%, start=${levels[0]}%, end=${levels.at(-1)}%`
);
}
}
if (level === undefined) {
console.log('🔴 Level not found');
}
level / 100;
}