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

Check if companion is runnning?

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
0 Votes
12 REPLIES 12

It sounds like the Fitbit mobile app is being killed due to battery optimization on your phone. Check your phone settings.

Best Answer
0 Votes

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

Best Answer

Put code in the companion to reply to messages. In your device, ensure that replies are received within a reasonable period of time.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Sounds 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 Answer
0 Votes

You could try onclose and maybe onerror.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Is there one for when the companion becomes active?

 

Best Answer
0 Votes

This 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 Answer
0 Votes

That 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 Answer
0 Votes

In 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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Ooh okay, sounds interesting

Will find out later today

Best Answer
0 Votes

You maybe could also use the launchReasons to detect why the companion has launched. Companion Guide (fitbit.com)

Best Answer
0 Votes

dismiss reply will try later

Best Answer
0 Votes