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

Companion is not doing its job. It's never awake or ready

This is constantly an issue. It should be updating the weather every 5 minutes based on this code. But it's not. I have to open another app on the Fitbit and return to the watch face just so it reloads with the up-to-date weather information.

 

 

const MILLISECONDS_PER_MINUTE = 1000 * 60;

// Tell the Companion to wake after 5 minutes
companion.wakeInterval = 5 * MILLISECONDS_PER_MINUTE;

// Listen for the event
companion.addEventListener("wakeinterval", queryTemperatureData);

// Event happens if the companion is launched and has been asleep
if (companion.launchReasons.wokenUp) {
queryTemperatureData();
}

 

 

 

I also have code in app/index.js that should be running once a day, but it's not because the companion refuses to be in ready step.

 

 

getTheData() 
  let keepTrying = true;
  if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
    // Send a command to the companion
    messaging.peerSocket.send({
      command: '<something>'
    });

    keepTrying = false;
  } else {
    console.log("The companion is ignoring me. Sending request, again in 5 seconds");
    if (keepTrying ) setTimeout(getTheData,5000);
  }
}

 

 

Why does this have to be so complicated and frustrating?  I finally bridged my phone and Fitbit, and I sit and watch the CLI terminal. 5 minutes later, nothing, not a single console.log entry. After like 10 minutes, it just goes to

 

Phone 'Google Pixel 7 Pro' disconnected
Device 'Sense' disconnected

 

 

 

Best Answer
0 Votes
4 REPLIES 4

If the intention of the companion's life cycle is run 1 time and only 1 time when the app/clockface is first initiated, and then permanently close after a few minutes, it would be helpful for Fitbit to admit to us and make it clear.

Using appbit.exit(); is the only way to reliably get the the messaging socket open for both the companion and the device. Why is it the companion is awake and active, and the socket is open when the device app restarts, but not at any other time?

 

Best Answer
0 Votes

I think there can be problems with messaging not reopening after closing. Can you do a test using file transfer instead? You may find that the companion is actually waking, but messaging is not being re-established.

Peter McLennan
Gondwana Software
Best Answer

I am currently in the process of adding file transfer. I haven't tested it on the actual device yet, but with the simulator, the file transfer is actively staying alive. So I am hopeful.

Best Answer

That's promising. I don't think the sim fully implements lifecycle events (wake interval, etc), so don't push too far without testing on real hardware.

Peter McLennan
Gondwana Software
Best Answer
0 Votes