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.
You listen for the sensor data, send it via messaging to the companion, then from the companion to your backend using fetch().
Take a look at the Sensors guide, Companion guide, and the Communications>Messaging guide.
Best AnswerCould you please give me a sample code to export accelerometer data? I could print it on the console while the app is being used and how can i get accelerometer data in the background?
import { Accelerometer } from "accelerometer";
import { Barometer } from "barometer";
import document from "document";
import { HeartRateSensor } from "heart-rate";
let accelData = document.getElementById("accel-data");
let barData = document.getElementById("bar-data");
let hrmData = document.getElementById("hrm-data");
let accel = new Accelerometer();
let bar = new Barometer();
let hrm = new HeartRateSensor();
accel.start();
bar.start();
hrm.start();
function refreshData() {
let data = {
accel: {
x: accel.x ? accel.x.toFixed(1) : 0,
y: accel.y ? accel.y.toFixed(1) : 0,
z: accel.z ? accel.z.toFixed(1) : 0
},
bar: {
pressure: bar.pressure ? parseInt(bar.pressure) : 0
},
hrm: {
heartRate: hrm.heartRate ? hrm.heartRate : 0
}
};
accelData.text = JSON.stringify(data.accel);
barData.text = JSON.stringify(data.bar);
hrmData.text = JSON.stringify(data.hrm);
console.log(accelData.text);
}
refreshData();
setInterval(refreshData, 1000);
Best AnswerAt the moment, user apps can't run in the background.
Best AnswerHi Catplace, thanks for the reply... Whenever i close the app on my Ionic i see "[1:01:17 PM]App Closed" and couldn't collect the accelerometer data. Are you saying that i cannot get accelerometer data in the background? How can i raw accelerometer data and send it to Azure cloud even when the app is not in use? or could it also be stored and then uploaded via wifi at the end of the day?
Best AnswerIt can't be done. Your app would need to run continuously.
Best Answer