I made an app on my Fitbit Versa 2 where I can control my garage door. It fetches an URL on my raspberry which triggers the garage. Sometimes nothing happens as the companion app is not running due to synchronisation errors (on the same time alexa is not working on my watch either).
Is there any way to test if the companion app is running and displaying the status? So I know if I have to get out my keys for the garage instead of the app.
Best Answer
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.
But how can we check if the companion is active, Messaging API still reads the socket as open even though messages sent aren't received by the companion in 4.3.0
Put code in the companion to reply to messages. In your device, ensure that replies are received within a reasonable period of time.
Best AnswerSounds good, however is there an event that knows when the companion becomes active from inactive? I just don't want to drain battery with message callbacks, and timely inform the user when the device is connected with the companion
Best AnswerIs there one for when the companion becomes active?
Best AnswerThis may not be exactly what you are looking for, but here's what I do to talk to my companion:
import { peerSocket } from "messaging";
const err_element = document.getElementById("err_element");
//send message to companion
function sendMessage() {
if (peerSocket.readyState === peerSocket.OPEN) {
// Send to the companion
peerSocket.send("Whatever I want");
}
else {
console.log("CONNECTION CLOSED");
err_element.style.display = "inline";
err_element.style.fill = "red";
}
}
// Listen for messages from the companion
peerSocket.onmessage = function(evt) {
console.log(evt);
}
// Listen for the onopen event
peerSocket.addEventListener("open", (evt) => {
// console.log("Ready to send or receive messages");
});
// Listen for the onerror event
peerSocket.addEventListener("error", (err) => {
console.log("Connection error: " + err.code + " - " + err.message);
});
Maybe you can rig something up that'll send a message every X seconds/mins or something to check connection, then if it fails, set an icon on your fitbit to a different color (which is what I do)
Best AnswerThat is a viable choice, however the problem is that if the user turned on their phone and their phone becomes active, it may take a few minutes.
Another consideration is that how frequent it checks also impacts battery.
I'm currently using Appbit API for the unload event, but where is the event when the companion becomes active is my question.
Best AnswerIn its startup code, you could get the companion to send a message to the watch.
However, the companion will only start when it needs to; eg, receiving a message or file, user starts settings, or wake interval.
Best AnswerOoh okay, sounds interesting
Will find out later today
Best AnswerYou maybe could also use the launchReasons to detect why the companion has launched. Companion Guide (fitbit.com)
Best Answerdismiss reply will try later
Best Answer