03-18-2019 02:42
03-18-2019 02:42
import * as messaging from "messaging";
// initialize variables
var dataArray = [];
var k = 0;
// append incoming data to dataArray
messaging.peerSocket.onmessage = function(evt) {
dataArray.push(evt.data);
//console.log('Receiver: toc')
}
function post(csv) {
const json = JSON.stringify(csv);
// API form data has has the fields "name" and "json_string" both taking strings
const formData = new FormData();
// k tells me the chunk number
formData.append('name', 'Filename ' + k.toString());
formData.append('json_string', json);
fetch('https://api_adress/', {method: 'POST', body: formData})
k = k + 1
}
function uploadFile(){
const len = dataArray.length
if (len >= 1000){
console.log(k.toString());
post(dataArray);
// reset dataArray
dataArray = [];
} else {
console.log("Not enough data to POST!")
}
}
setInterval(uploadFile, 30000);
uploadFile()Hey everyone,
my situation is as follows: I have written an app that sends raw accelerometer and gyroscope data via messaging to the Companion app (running on an Android phone). There, the data points are appended to an array and - once the array exceeds a predefined length - sent to an API via "fetch".
The frequency of incoming data to the Companion is once every 50 ms (sampling rate of 20 Hz). For small array sizes (200 rows) everything works smoothly. If I however increase the chunk size to say 1000, it only manages to send two chunks to my API and then the console says "App closed on device". Of course, I did not close it manually. There are no errors during the process.
I am really out of my wits and would be grateful if any of you has an idea. I include a minimal version of the companion code.
Best
Simon
Answered! Go to the Best Answer.
Best Answer03-18-2019 03:37
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.
03-18-2019 03:37
Sounds like the AppTimeout. https://dev.fitbit.com/blog/2018-10-05-announcing-fitbit-os-2.2/#app-timeout-api
Also, I would not rely on your setInterval as the companion may be suspended, instead, either use wakeInterval or check the length when you receive a message from the device.
Best Answer03-18-2019 03:37
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.
03-18-2019 03:37
Sounds like the AppTimeout. https://dev.fitbit.com/blog/2018-10-05-announcing-fitbit-os-2.2/#app-timeout-api
Also, I would not rely on your setInterval as the companion may be suspended, instead, either use wakeInterval or check the length when you receive a message from the device.
Best Answer03-18-2019 03:48
03-18-2019 03:48
Thank you SO much for your quick response. I don't have my device right here but once I tried turning the timeout off and everything works (which I strongly expect) I will give your answer the "Accept as Solution" check.
Best
Simon
Best Answer