Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sensor Data Freezing with File Transfer API

My app is collecting some sensor data on Versa 3 and sending it via File Transfer API to the companion. After an unpredictable amount of time (highly variable each time), the sensor data freezes (becomes constant) and the data is no longer sent to the companion. I am also cleaning my cue outbox and deleting files in FitBit memory so those could not be the problem

 

Is there some sort of OS intervention? What could be the reason? 

 

I appreciate help

Best Answer
0 Votes
6 REPLIES 6

Is it an app or a clock?

How long typically does it last before freezing?

Have you checked the memory usage for a leak? https://dev.fitbit.com/build/reference/device-api/system/#variable-memory

Does relaunching the app fix it, or do you have to reboot?

Which device & firmware version?

Does it do the same in the simulator?

Best Answer

Thanks Jon for your response.

So, it is an app. The device app takes batch readings from heart rate and acceleration ... formats them into json arrays ... then puts the json arrays into a file and uses the file transfer API to send the file to companion ... the companion sends each json string to a google cloud server.

 

We checked the memory ... we are not running over ... We seem to freeze every couple of hours or so but I added a button that restarts the sensors and that seems to unfreeze the app until it freezes again. 

 

Relaunching the app or rebooting the Fitbit unfreezes it yeah. The device is versa 3 with SDK version 5.0.   Yeah same in the simulator with no errors shown ... the print statements in the console just stop with no errors.

Best Answer
0 Votes

I wonder if the Fitbit mobile app is getting suspended for battery optimisation. Can you check the settings on your phone?

 

There's a couple of things you might try:

 

1. Companion wakeInterval every 10 mins

2. Send a ping from the device to companion, then reply from the companion to the device. Use the Messaging API for this.

Best Answer
0 Votes

Thanks for your response. Will implement this and let you know. As I read batch readings, I also update them on the Fitbit device UI and when the app crashes, every time the sensor readings also stay constant and stop changing on the Fitbit screen. This is independent of the companion. Based on this, I believe the error is coming from the Batch readings. In addition, when I restart the sensors using the sensor API (for example hrm.stop()), the app starts working again for a short time and crashes again. Is the sensor batch reading likely to freeze and is there anyway to make it more robust for longer periods of time without crashing?

Best Answer
0 Votes

I see, that does sound more like the sensors then. Which sensors are you running concurrently and which options are you using for them?

Best Answer
0 Votes

I am running body presence (without batch) and heart rate and accelerometer with batch (frequency: 1, batch: 30). Basically, for each batch reading I create a json file and queue it using File Transfer API to companion. This is my code for heart rate for instance:

 

if (HeartRateSensor) {
const hrm = new HeartRateSensor({ frequency: 1, batch: 30 });
hrm.addEventListener("reading", () => {
var biglist = [];
for (let index = 0; index < hrm.readings.timestamp.length; index++) {

var dt = Date.now() + (1000*index);
var date = new Date(dt);

var json_data = {
"data": "HRM: " + hrm.readings.heartRate[index],
"timestamp": String(date),
"bps": JSON.parse(bpsData.text).presence,
"device_ID": device_ID_num.toString(),
"device_ID_and_date": device_ID_num.toString() + " " + "HRM" + " " + date,
"Sleep_State": sleep.state
};

biglist.push(json_data);
 
if (index == hrm.readings.timestamp.length-1) {

num_files_hrm = num_files_hrm + 1;
var num_files_String = (num_files_hrm).toString();
var filename = num_files_String + "_hrm" + ".txt";
fs.writeFileSync(filename, biglist, "json");
 
var file_directory = "/private/data/" + filename;

outbox
.enqueueFile(file_directory)
.then(ft => {
console.log(`Transfer of ${ft.name} successfully queued.`);
})
.catch(err => {
console.log(`Failed to schedule transfer: ${err}`);
})

 
var num_files_before = num_files_hrm - 1;
 
var num_files_before_final = num_files_before.toString() + "_hrm";
fs.unlinkSync(num_files_before_final + ".txt");
}

}
})
 
hrm.start();
}
Best Answer
0 Votes