Hello
I'm working on an app which involves fetching from an API every minute and updating the text on screen. I don't know where to start, as all the examples need input from the companion. Could someone help me get started?
Thanks
Best AnswerWell the companion goes to sleep, so wake it up. https://dev.fitbit.com/build/reference/companion-api/wake-interval/
Then use the fetch api https://dev.fitbit.com/build/reference/companion-api/fetch/
Then send a file to the watch https://dev.fitbit.com/build/reference/companion-api/file-transfer/
Then read the file on the watch.
mport { me as companion } from "companion";
if (!companion.permissions.granted("run_background")) {
console.warn("We're not allowed to access to run in the background!");
}
const MILLISECONDS_PER_MINUTE = 1000 * 60;
// Tell the Companion to wake after 30 minutes
companion.wakeInterval = 30 * MILLISECONDS_PER_MINUTE;
// Listen for the event
companion.addEventListener("wakeinterval", doThis);
// Event happens if the companion is launched and has been asleep
if (companion.launchReasons.wokenUp) {
doThis();
}
function doThis() {
console.log("Wake interval happened!");
}
Best Answer