Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Best AnswerI've managed to store a whole day's data comprising energy, distance, steps, active minutes, altitude and heart-rate, sampled at 15-second intervals. This took me six files of 11,522 bytes each (with each value stored as an Int16 to conserve app memory).
Best AnswerSorry, I mislead you. One large file should be fine, so long as you don't try to get it all in memory at once.
I used Int16Array for in-memory buffers. You can read and write these to binary files using, eg, writeSync().
Best AnswerI don't think you can truncate a file, but you can write new data to any location within it. I use this method, and keep track of which bits of the file contain valid data using in-memory variables (carefully saved and restored when necessary). You could also write 'invalid'/'empty' sentinel values to the file.
This is perhaps inefficient, but I've found that it's a lot quicker to create a fixed-length file and then use it like an array, reading and writing data in blocks whenever possible. Iterating through hundreds of values in JS code can get your app killed for unresponsiveness (although you could put timeouts in slow code, but then you have to deal with possible events while your data is in an indeterminant state).
In my case, I knew that I'd want a value for every 15 seconds, so I just use files that contain exactly 24*60*60/15 Int16s. To avoid having to create and initialise such files on the device (which is slow), my app ships with a pre-created empty file of that length. Duplicating it is quick because it can be done in a few file system calls; no looping is required.
Best Answer